This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Possible gcc 3.4/4.0 bug wrt template dependant lookup
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: "Pollard, Andrew" <andrew dot pollard at brooks dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 16 Nov 2004 17:55:49 +0000
- Subject: Re: Possible gcc 3.4/4.0 bug wrt template dependant lookup
- Organization: Codesourcery LLC
- References: <B0EF51D84DDEEF4D9F7D485485751F6C075EA5@mail-brooks5.brooks.com>
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