[Bug c++/14132] New: static template member definition fails
guillaume dot melquiond at ens-lyon dot fr
gcc-bugzilla@gcc.gnu.org
Thu Feb 12 19:17:00 GMT 2004
Hi,
This bug is the same as PR11585 but I'm not convinced by its conclusion. However
I didn't know if I should have reopened the bug or created a new one.
The test-case is:
template< class T > struct A { static int a; };
int A< void >::a;
With GCC 3.3 and Intel CC 8.0, the code compiles just fine. But GCC 3.4
(20040211 snapshot) complains: "plouf.cc:2: error: too few
template-parameter-lists". In order for GCC 3.4 to accept the code, "template<>"
must be added in front of the second line (it's the solution suggested in PR11585).
Unfortunately, adding "template<>" does change the meaning of the line since GCC
will not create an instance of "A<void>::a" anymore and the following testcase
will not be linkable:
template< class T > struct A { static int a; };
template<> int A< void >::a;
int main() { A< void >::a = 0; }
/tmp/ccgh5JJQ.o(.text+0x1e): dans la fonction « main »:
: undefined reference to `A<void>::a'
It fails to link with GCC 3.3, 3.4 and ICC 8.0. But removing the "template<>"
allows the program to cleanly compile and link with both GCC 3.3 and ICC 8.0. So
what's the solution?
Please consider this bug-report as a wish item for the C++ language improvements
section of http://gcc.gnu.org/gcc-3.4/changes.html since it is quite a common
case when programing with templates and static members.
--
Summary: static template member definition fails
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: guillaume dot melquiond at ens-lyon dot fr
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14132
More information about the Gcc-bugs
mailing list