3.4 Bug? template dependent name lookup fails from template functions

Nathan Sidwell nathan@codesourcery.com
Thu Apr 15 13:07:00 GMT 2004


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




More information about the Gcc mailing list