Bug in choice of template specializations

Ewgenij Gawrilow gawrilow@math.TU-Berlin.DE
Mon Mar 6 03:23:00 GMT 2000


The template partial specializations with local classes of template classes as
explicit parameters seem to be ignored by gcc. As far as I understand the
playing rules, the following program should print the "spec" message four times.


#include <iostream>

class A {
public:
   class local { };
};

class B {
public:
   template <class X>
   class local { };
};

template <class X>
class C {
public:
   class local { };
};

template <class X>
class D {
public:
   template <class Y>
   class local { };
};

template <class X> class S {
public:
   static const char* who() { return "primary"; }
};

template <> class S<A::local> {
public:
   static const char* who() { return "A spec"; }
};

template <class X> class S<B::local<X> > {
public:
   static const char* who() { return "B spec"; }
};

template <class X> class S<C<X>::local> {
public:
   static const char* who() { return "C spec"; }
};

template <class X, class Y> class S<D<X>::local<Y> > {
public:
   static const char* who() { return "D spec"; }
};

template <class X>
const char* who(const X&) { return S<X>::who(); }

int main()
{
   A::local a;
   B::local<int> b;
   C<int>::local c;
   D<int>::local<int> d;
   cout << "a: " << who(a) << endl;
   cout << "b: " << who(b) << endl;
   cout << "c: " << who(c) << endl;
   cout << "d: " << who(d) << endl;
   return 0;
}


Compiled with gcc 2.95.2, it prints however:
a: A spec
b: B spec
c: primary
d: primary


The system environment is as follows:

% uname -a
SunOS sokol 5.7 Generic_106541-08 sun4u sparc SUNW,UltraSPARC-IIi-Engine

% g++ -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)

% cat tmp/gcc-build/config.status 
#!/bin/sh
# This file was generated automatically by configure.  Do not edit.
# This directory was configured as follows:
.../tmp/gcc-2.95.2/configure --with-gcc-version-trigger=.../tmp/gcc-2.95.2/gcc/version.c --host=sparc-sun-solaris2.6 --enable-shared --enable-version-specific-runtime-libs --enable-languages=c++ --with-gxx-include-dir=/usr/local/include/C++ --norecursion 
# using "mh-frag" and "mt-frag"


With best regards,
Ewgenij Gawrilow
Dept. of Mathematics, Technical University of Berlin


More information about the Gcc-bugs mailing list