// A template class. template< typename, typename > struct f {}; // A template function that calls a member template function. template< typename T > void call_f( T& t ) { t.template f< int >(); // t.T::template f< int >(); // this line works }
struct F { template <typename> void f() {} }; int main() { F obj; call_f(obj); } GCCs 3.4 - 4.1 error with: phil2.cc: In function void call_f(T&): phil2.cc:8: error: wrong number of template arguments (1, should be 2) phil2.cc:2: error: provided for template<class, class> struct f Shouldn't the lookup of the id-expression "template f<int>" be done in the scope of T according to 3.4.5/2, so shouldn't it be ignoring ::f ? If you qualify the function call with "T::" it works as expected. If either ::f or ::call_f() is not a template, it works. I expect the template-id "template f<int>" to be dependent on T, so get looked up at the point of instantiation, in the scope of F, finding F::f. It seems that either it isn't dependent (in which case it should not find F::F if you comment out the declaration of ::f) or something means that lookup of a template, within a template disregards 3.4.5/2. Or it's a bug, but I'm not convinced I haven't overlooked something. -- Summary: Lookup of template member function finds global type. Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: redi at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24161