This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible gcc 3.4/4.0 bug wrt template dependant lookup


Pollard, Andrew wrote:
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());    }

to continue,
template<typename T> struct M { int bar() { return (foo(T())); } };

ie, remove the :: qualification on foo, it returns 0.
yes, because now it is a dependent expression, fitting the syntax of
[14.6.2].  Thus lookup is done at instantiation time in both the
context of the definition AND of the instantiation.  Hence we find
both overloads of ::foo, deduce both successfully and find that the
second one is more specialized than the first.

Also, if I move the 'struct M' to after the foo() specialization for
S<T>,
it also returns 0 (with or without the :: qualification)
Yes, because both overloads are visible at definition time, and bound
then (overload resolution itself occurs at instantiation time when T is
known).


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)
yes it is doing that, because that's what the std says :)

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]