This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 3.4 Bug? template dependent name lookup fails from template functions
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Michael Veksler <VEKSLER at il dot ibm dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 15 Apr 2004 12:23:44 +0100
- Subject: Re: 3.4 Bug? template dependent name lookup fails from template functions
- Organization: Codesourcery LLC
- References: <OF9C85106F.BB64CE67-ONC2256E77.003A7088-C2256E77.003C2E00@il.ibm.com>
Michael
$ cat t7.cc
void F(int) {}
void F(char) {}
template <class T> struct A {};
template <class T>
void F(const A<T> & )
{
T t;
F(t); // ok for T=double
::F( t ); // fails for T=double, does not find F(double)
}
void F(double) { } // This will be found, if moved before F<T>
int main()
{
A<double> a;
F(a); // shouldn't ::F(T) [for T=double] be looked up here?
}
$ $gcc34/bin/g++ -c t7.cc
t7.cc: In function `void F(const A<T>&) [with T = double]':
t7.cc:18: instantiated from here
t7.cc:11: error: call of overloaded `F(double&)' is ambiguous
t7.cc:1: note: candidates are: void F(int)
t7.cc:2: note: void F(char)
The :: operator is unavoidable when F is a template member function.
Also, I thought that '::F(T)' is a template dependent name that should
be looked up only during template instantiation.
no, it is not. [14.6.2] says
postfix-expression (expression-list-opt)
is only dependent if
1) postfix-expression is an identifier
2) at least one expression in the list has dependent type
::F is not an identifier, therefore ::F(a) is bound to the set of ::F visible
in the template definition.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk