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: 3.4 Bug? template dependent name lookup fails from template functions


Michael Veksler <VEKSLER@il.ibm.com> writes:

> The following behavior of gcc looks wrong. I could not find anything in 
> the
> standard that states otherwise. Just look at the following example and the
> error that follows.
> 
> Am I right, and GCC contains a bug? If so, should I file a bug report
> with target gcc-3.4.1 ?
> 
> 
>    $ 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)

14.6.2/1, which defines dependent names, says in part :

#    [snip] ... In an expression of the form:
#
#        postfix-expression ( expression-list ... )
#
#    where the postfix-expression is an identifier, the identifier
#    denotes a dependent name ... [snip]

'::F' isn't an identifier. It's a qualified-id. I think only operators
    and identifiers can be dependent names. So '::F' is not a
    dependent name.

More, only argument dependent lookup is done in both the context of
    the definition and the point of instantiation. Qualification
    supresses argument definition lookup.

So I think gcc 3.4 is right to do this. However, you should take this
    up on comp.std.c++ or comp.lang.c++.moderated , where there are
    more C++ experts. (note: I am not an expert.)

However - this can't be the end of it; comeau online reports errors
    for *both* calls to F, unlike gcc 3.4 which at least accepts the
    first call.

>    }
>    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)
> 
>    $ $gcc34/bin/g++ -v
>    Reading specs from 
> /home/veksler/gcc/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
>    Configured with: ../gcc-3.4.0-20040406/configure 
> --prefix=/home/veksler/gcc --enable-languages=c++
>    Thread model: posix
>    gcc version 3.4.0 20040407 (prerelease)
> 
> 
> 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.


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