[Bug c++/36151] New: gcc fails to find template specializations within namespace

juergen dot wallner at philips dot com gcc-bugzilla@gcc.gnu.org
Tue May 6 10:07:00 GMT 2008


Compiling the following code fails with g++ 4.2.1 (also with 4.1.3 and 4.3.0
but works with 4.0.1 and 4.0.2)
--
template<class T> class A
{
public:
        T& operator*() { return *m; }
        T *m;
};

template<class T> class B
{
public:
        T& operator*() { return *m; }
        T *m;
};

class X
{
public:
        void foo() {}
};

namespace N {
        template<class T> void bar( T& v )              { v.foo(); }
        template<class T> void bar( B<T>& x )           { bar( *x ); }
        template<class T> void bar( A<T>& x )           { bar( *x ); }
}

int main()
{
        B< A<X> > m;
        N::bar( m );
};
--
Output of g++ -c testfile.cpp:
testfile.cpp: In function 'void N::bar(T&) [with T = A<X>]':
testfile.cpp:23:   instantiated from 'void N::bar(B<T>&) [with T = A<X>]'
testfile.cpp:30:   instantiated from here
testfile.cpp:22: error: 'class A<X>' has no member named 'foo'
--
Somehow the compiler doesn't seem to see the template specialization for A<X>
and takes the more general template instead - I consider this a bug BECAUSE:

1.) This code compiles with reversed order of template specialization
definition OR template nesting - i.e. the above example will work with "A< B<X>
> m;"
2.) Code compiles with namespace consistently removed (any order of
definitions/nesting).
--
Output of g++ -v:
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info --mandir
=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=rel
ease --with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp
--disable-libssp --disable-libgcj --with-slibdir=/lib --with-system-
zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --program-suffix=-4.2 --enable-v
ersion-specific-runtime-libs --without-system-libunwind --with-cpu=generic
--host=i586-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)
--
identical behaviour observed with 
4.1.3 (i586-suse-linux)
4.3.0 (powerpc-apple-darwin8)
known to work with
4.0.1, 4.0.2 (both platforms mentioned)


-- 
           Summary: gcc fails to find template specializations within
                    namespace
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: juergen dot wallner at philips dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36151



More information about the Gcc-bugs mailing list