When compiling and running the code
#include <iostream>
struct A { A(int){} };
void foo( int ) { std::cout << "foo(int)" << std::endl; }
template< typename T >
struct S {
void bar() { foo( 5 ); }
void foobar() { T t = 5; foo(t); }
};
inline void foo( A ) { std::cout << "foo(A)" << std::endl; }
inline void foo( double ) { std::cout << "foo(double)" << std::endl; }
int main(int argc, char* argv[])
{
S<double> s0;
s0.bar();
s0.foobar();
std::cout << '\n';
S<A> s1;
s1.bar();
s1.foobar();
}
I get the output (using g++ 4.8, clang++ 3.2 or icpc 13.1)
foo(int)
foo(int)
foo(int)
foo(A)
While the last two lines make perfect sense to me considering the two-phase lookup rules, I would expect foo(int) foo(double)
for the first two lines.
It seems that in this case for the foobar()
call foo()
gets looked up before instantiation which should not be possible. Any hints?