[Bug c++/12222] explicit initialization of static template members seems ignored
bangerth at dealii dot org
gcc-bugzilla@gcc.gnu.org
Tue Sep 9 14:08:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12222
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-09-09 14:08:31
date| |
------- Additional Comments From bangerth at dealii dot org 2003-09-09 14:08 -------
Your code is invalid: you have the explicit instantiation before the declaration
of an explicit specialization of the member. That confuses the compiler. If you
revert the order, you get this error message:
tmp/g> ../build-gcc/gcc-install/bin/c++ x.cc -W -Wall
/tmp/ccQIMlpO.o(.text+0x11): In function `main':
: undefined reference to `a<float>::b1'
collect2: ld returned 1 exit status
That is due to the fact that you only _declare_ the existence of an explicit specialization,
not define it. If instead of
template <> b a<float>::b1;
you write
template <> b a<float>::b1 = b();
then the code compiles properly and yields the expected result.
Now, this is indeed confusing -- gcc should be able to issue a warning about specializing
after instantiating. Besides, there is kind of a bug anyway: when accessing
a<float>::b1.m, gcc is apparently presently using the static member from the general
template, not the specialization. That's fine, because the code is invalid. However, it
is equally apparently not initializing it properly, since otherwise we would get the
right answer.
W.
More information about the Gcc-bugs
mailing list