Possible gcc 3.4/4.0 bug wrt template dependant lookup

Pollard, Andrew andrew.pollard@brooks.com
Tue Nov 16 17:35:00 GMT 2004


The program in question is
 
foo.cxx:
------------------------------------
template<typename T> int foo(const T&)      { return (1);          }
template<typename T> struct M { int bar()   { return (::foo(T())); } };
template<typename T> struct S { int bar()   { return (T(0));       } };
template<typename T> int foo(const S<T>& s) { return (s.bar());    }
 
int
main()
{
    M<S<int> > q;
    return (q.bar());
}
------------------------------------
 
% g++34 foo.cxx; ./a.out; echo $?
1
% g++40 foo.cxx; ./a.out; echo $?
1
% g++33 foo.cxx; ./a.out; echo $?
0
 
If I change line 2 to be
 
template<typename T> struct M { int bar()   { return (foo(T())); } };
 
ie, remove the :: qualification on foo, it returns 0.
 
Also, if I move the 'struct M' to after the foo() specialization for S<T>,
it also returns 0 (with or without the :: qualification)
 
It is as if the :: qualification is stopping the bar() method being template
type dependent, and binding the call at parse time and not at instantiation
time (in this case, getting the base template for foo() and not the specialization)
 
What, if anything, am I missing?
 
Thanks,
 Andrew.



More information about the Gcc mailing list