The code: -------- template<class PRI, class SEC> struct is_same { enum { value = false }; }; template<class PRI> struct is_same<PRI,PRI> { enum { value = true }; }; struct JCF { JCF(int i = is_same<int,int>::value ) {} /// parse error in this line }; The error: --------- x.cpp:10: parse error before `>' token x.cpp:10: missing ';' before right brace gcc -v -save-temps output ------------------------- $ gcc -v -save-temps Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/specs Configured with: ../configure --prefix=/usr --libdir=/usr/lib --with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --enable-long-long --enable-__cxa_atexit --enable-languages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu --with-system-zlib Thread model: posix gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk) Additional Builds and Platforms ------------------------------- Also occurs on gcc 3.2 on Solaris 2.6
I can confirm this on the mainline (20031006). ICC accepts this. A workaround is to use a static constant variable in the struct JCF.
The problem is not that specialization is there but GCC rejects the default value of using a template with two arguments. For an example: template<class PRI, class T> struct is_same { static const int value = false; }; struct JCF { JCF(int i = is_same<int, int>::value ) {} /// parse error in this line };
There is a workaround that works for some cases. template<class T,class U> struct X { static const int value = 1; }; struct Y { typedef X<int,int> XIntInt; Y(int i = XIntInt::value) {} }; It does not apply to some template constructors: struct Y { // typedef X<???,???> XT1T2; template<class T1> T ( int i = X<T,T>::value) {} };
It's a duplicate of an old bug report PR57. It waits for the resolution of core issue 325. *** This bug has been marked as a duplicate of 57 ***