Possible gcc 3.4/4.0 bug wrt template dependant lookup
Pollard, Andrew
andrew.pollard@brooks.com
Tue Nov 16 17:51:00 GMT 2004
Hi all,
[ Using gcc-3.4.4-20041116 and gcc-4.0.0-20041116 ]
I don't know whether this is a gcc bug, or Standard mandated behaviour
with
the two stage dependant name lookup in templates. Can someone here
clarify?
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.
--
Andrew Pollard - Senior Software Engineer
Brooks Automation - Software Systems Group (APF)
Andrew.Pollard@brooks.com : +44 (0)118 9215603
More information about the Gcc
mailing list