Bug 12531 - Default value of a template with two template arguments not accepted
Summary: Default value of a template with two template arguments not accepted
Status: RESOLVED DUPLICATE of bug 57
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-10-06 21:15 UTC by jfranzoy
Modified: 2003-10-18 16:54 UTC (History)
2 users (show)

See Also:
Host: mandrake linux 586
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-10-14 19:14:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jfranzoy 2003-10-06 21:15:43 UTC
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
Comment 1 Andrew Pinski 2003-10-07 01:48:30 UTC
I can confirm this on the mainline (20031006).  ICC accepts this. A workaround is to use a static 
constant variable in the struct JCF.
Comment 2 Andrew Pinski 2003-10-07 01:51:53 UTC
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
};
Comment 3 jfranzoy 2003-10-07 14:10:10 UTC
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) {}
};
Comment 4 Kriang Lerdsuwanakij 2003-10-18 16:54:58 UTC
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 ***