Topic: Quirk of ADL and templates, or G++ bug?


Author: kanze@gabi-soft.de (James Kanze)
Date: Tue, 30 Jul 2002 17:25:21 GMT
Raw View
Given the recent discussions of ADL and templates, I'm not sure of
anything any more.  I have the following program:

    template< typename T >
    unsigned
    h( T const& ob )
    {
        return 0 ;
    }

    template< typename T >
    struct Traits
    {
        static unsigned h( T const& obj )
        {
            return ::h< T >( obj ) ;    //  line 14
        }
    } ;

    typedef int C ;

    void
    f()
    {
        C       unC ;
        unsigned u = Traits< C >::h( unC ) ;
    }

When I compile it with g++ (3.1), I get an error:

    tmplt.cc: In static member function `static unsigned int Traits<T>::h(const T&)
       [with T = C]':
    tmplt.cc:24:   instantiated from here
    tmplt.cc:14: no matching function for call to `Traits<C>::h(const int&)'

If I suppress the < T > (which strictly speaking aren't necessary), it
compiles.  If I wrap both h and Traits in a namespace, and qualify the
call with the namespace, it also compiles.  Is this another unintuitive
quirk of template name lookup, or is it a g++ bug?  (The code compiles
with Sun CC 5.1, but this may just be because Sun is pretty leniant
about accepting pre-standard code.)

--
James Kanze                           mailto:jkanze@caicheuvreux.com
Conseils en informatique orient   e objet/
                    Beratung in objektorientierter Datenverarbeitung

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gabriel Dos Reis <gdr@soliton.integrable-solutions.net>
Date: Tue, 30 Jul 2002 18:00:38 GMT
Raw View
kanze@gabi-soft.de (James Kanze) writes:

[...]

| Is this another unintuitive
| quirk of template name lookup, or is it a g++ bug?

A bug in the compiler.

--
Gabriel Dos Reis, gdr@integrable-solutions.net

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]