Funky templates in namespaces crash g++

Lauri Alanko la@iki.fi
Fri Apr 16 14:40:00 GMT 1999


Hello, there.

Problem: Trying to compile this code with NAMESPACE defined causes an
internal compiler error. When the template is outside namespaces, it
works all right.

Full error message:
g++ -DNAMESPACE -Wall -W -Winline -ansi -pedantic -save-temps -c t.C -o t.o
t.C: In instantiation of `Check<X,int>':
t.C:25:   instantiated from `::N::::N::Check<X,int>'
t.C:25:   instantiated from here
t.C:25: Internal compiler error.
t.C:25: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
t.C:25: See <URL: http://egcs.cygnus.com/faq.html#bugreport > for details.

The code in question (a pretty minimal example):
#ifdef NAMESPACE
namespace N {
#endif
template <class Base, class Derived>
class Check {
	struct Big {
		int x[2]; 
		static Big f(void *)
			{return Big ();}
		static char f (Base*)
			{return 1;}
	};
public:
	enum{isA = (sizeof(Big::f(static_cast<Derived*>(0))) == 1)};
};
#ifdef NAMESPACE
}
using namespace N;
#endif

class X;

template <class T, bool N = Check<X, T>::isA> class RP;

RP<int> * q;

Compiler version:
$ g++ -v    
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release)

System: Linux/i386 2.2.5-ac4, glibc 2.1.1

WTF is that template supposed to do: See
http://lazy.ton.tut.fi/~esap/instructive/simulating-constrained-genericity.html


I hope this information is sufficient. Please try to get this fixed.

Thanks,


Lauri Alanko
la@iki.fi


More information about the Gcc-bugs mailing list