BEGIN_TESTCASE
#include <iostream>
using namespace std;

class C {
public:
   template<int V> int f();
};

template<> int C::f<0>() { return 10; }
template<> int C::f<1>() { return 11; }

template<class TC, int V>
class Cx {
public:
   int fx(TC*);
};

template<class TC, int V> int Cx<TC, V>::fx(TC* tc)  { return tc->f<V>(); }

int main()
{
   C c;
   Cx<C,0>* c0 = new Cx<C,0>;
   Cx<C,1>* c1 = new Cx<C,1>;
   cout << c0->fx(&c) << endl;
   cout << c1->fx(&c) << endl;
   delete c1;
   delete c0;   
   return 0;
}
END_TESTCASE

Test case fails to compile with vanilla GCC 4.2.3 x86_64 and i386.
Checked RH 3.4.6 and RH compat 3.2.3, also fails.

testcase.C:18: error: expected primary-expression before ')' token
testcase.C:18: error: invalid operands of types '<unresolved overloaded
function type>' and 'int' to binary 'operator<'

Compiles and runs correctly under

Sun32:  CC: Forte Developer 7 C++ 5.4 Patch 111715-13 2003/12/11
Sun64:  CC: Forte Developer 7 C++ 5.4 Patch 111715-13 2003/12/11
IBM32:  XL C++ 8.0.0.17
IBM64:  XL C++ 8.0.0.17
MS32: Microsoft 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
MS64: Microsoft C/C++ Optimizing Compiler Version 14.00.50727.762 for x64

Curiously fails with EDG (ICC 10.1.014), but this may
be due to EDG support of GCC bugs per
http://www.edg.com/index.php?location=c_lang
   "A GNU C and C++ compatibility mode, which provides the extensions supported
by GCC (versions 3.2-4.2), along with various undocumented features and bugs."

Lexical support laid out in first paragraph of ISO 14882:

3.4.5 Class member access [basic.lookup.classref]
In a class member access expression (5.2.5), if the . or -> token is
immediately followed by an identifier followed by a <, the identifier must be
looked up to determine whether the < is the beginning of a template argument
list (14.2) or a less-than operator. . .

Would greatly appreciate fix on high priority track with 4.2.3 patch as this
critical for us.


-- 
           Summary: explicit member function template lookup fails from
                    templated function
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: starlight at binnacle dot cx


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36203

Reply via email to