We've uncovered a GCC 4.1.1 template bug when we compile using GCC4.1.1,This simple testcase shows the issue. #include <iostream> template< typename T > void foo( T var) { std::cout << "T" << std::endl; } template < typename T> void doit( T var ) { foo(var); } void foo(const int& var) { std::cout << "INT" << std::endl; } int main() { doit(3); // prints T return 0; } /////////////// temp.cpp //////////////////////////////// Run the example with gcc 3.2.3 rm -f a.out $/v3.2.3/bin/g++ -Wall temp.cpp LD_LIBRARY_PATH=/v3.2.3/lib:$LD_LIBRARY_PATH; a.out [~/test]$ gcc3 INT Now run with GCC 4.1.1 [~/test]$ more gcc4 rm -f a.out $/v4.1.1/bin/g++ -Wall temp.cpp LD_LIBRARY_PATH=/v4.1.1/lib:$LD_LIBRARY_PATH; a.out [georgef@sdvlx32 ~/test]$ gcc4 T We can fix this particular example by moving void foo(const int& var) { std::cout << "INT" << std::endl; } to the top of the function. However, this won't work in more complex cases.
Created attachment 13146 [details] test case
Actually this is not a bug. The overloaded set for foo in doit is only the template foo and nothing else.
No, this is a bug, 2nd stage name-lookup should find foo(const int&) as var is dependent on the template parameter T (14.6/8, /9). But I bet we have a dup for this.
(In reply to comment #3) > No, this is a bug, 2nd stage name-lookup should find foo(const int&) as var is > dependent on the template parameter T (14.6/8, /9). > But I bet we have a dup for this. 14.6.4.2/1 says this is invalid code. For a function call that depends on a template parameter, if the function is an unqualified-id but not a template-id, the candiate functions are found using the usual lookup rules (3.4.1, 3.4.2) except that: .... Paraphasing since I don't want to type it all in * non argument dependent lookup (3.4.1: template definition context * argument dependent lookup (3.4.2): template definition context and template instation context Since the type is a fundamental type, argument dependent lookup does not apply, therefor this is not a bug.