finding a function-template

Toon Knapen
Tue Feb 8 12:46:00 GMT 2005

The example below compiles succesfully with all gcc's pre 3.4, icc, xlC 
(IBM) but not with gcc-3.4.3. Is gcc-3.4.3 wrong or not? I guess the 
different behaviour of gcc-3.4.3 is because of the two-phase lookup, 
although xlC also has two-phase lookup.

This example compiles succesfully with gcc-3.4.3 if the definition of 
the function 'foo(B)' is moved before the definition of 'bar()'.

#include <iostream>

struct A {} ;
struct B {} ;

template <class T>
void foo(A) { std::cout << "foo(A)" << std::endl ; }

template <class T>
void bar() { foo< T >(B()) ; }

template <class T>
void foo(B) { std::cout << "foo(B)" << std::endl ; }

int main()
    bar< int >() ;
    return 0 ;


More information about the Gcc-help mailing list