public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12222] explicit initialization of static template members seems ignored
       [not found] <bug-12222-4@http.gcc.gnu.org/bugzilla/>
@ 2012-02-01  3:07 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-01  3:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12222

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stephane at magnenat dot
                   |                            |net

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-01 03:07:04 UTC ---
*** Bug 46290 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/12222] explicit initialization of static template members seems ignored
  2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
                   ` (3 preceding siblings ...)
  2003-12-26 23:36 ` pinskia at gcc dot gnu dot org
@ 2004-08-16 18:37 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-08-16 18:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-16 18:37 -------
gcc's behavior actually makes a lot more sense than anyone seems to 
have noticed: with this code 
---------------- 
template <typename T> 
struct a { static int b1; }; 
 
template struct a<float>; 
template <> int a<float>::b1; 
 
int x = a<float>::b1; 
----------------- 
we indeed get no warning that a specialization is declared after  
instantiating the template. However, that's about ok: we haven't 
provided a definition of the static member, so it isn't instantiated 
and the declaration of the specialization doesn't come too late. 
 
On the other hand, for this code (not the presence of the definition) 
------------------ 
template <typename T> 
struct a { static int b1; }; 
template <typename T> int a<T>::b1; 
 
template struct a<float>; 
template <> int a<float>::b1; 
 
int x = a<float>::b1; 
------------------ 
we _do_ get an error: 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -Wall -c x.cc 
x.cc:6: error: redefinition of `int a<float>::b1' 
x.cc:3: error: `int a<float>::b1' previously declared here 
 
I think gcc is correct here. So closing. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12222


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/12222] explicit initialization of static template members seems ignored
  2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
                   ` (2 preceding siblings ...)
  2003-09-09 18:57 ` bangerth at dealii dot org
@ 2003-12-26 23:36 ` pinskia at gcc dot gnu dot org
  2004-08-16 18:37 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-26 23:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-26 23:17 -------
It might be that the C++ standard does not require a diagnostic of the problem.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12222


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/12222] explicit initialization of static template members seems ignored
  2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
  2003-09-09 14:08 ` [Bug c++/12222] " bangerth at dealii dot org
  2003-09-09 17:53 ` stefaandr at hotmail dot com
@ 2003-09-09 18:57 ` bangerth at dealii dot org
  2003-12-26 23:36 ` pinskia at gcc dot gnu dot org
  2004-08-16 18:37 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2003-09-09 18:57 UTC (permalink / raw)
  To: gcc-bugs

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



------- Additional Comments From bangerth at dealii dot org  2003-09-09 18:57 -------
That's your problem -- declaring an explicit specialization in a place where the 
compiler can't see it invokes undefined behavior. 
 
W.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/12222] explicit initialization of static template members seems ignored
  2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
  2003-09-09 14:08 ` [Bug c++/12222] " bangerth at dealii dot org
@ 2003-09-09 17:53 ` stefaandr at hotmail dot com
  2003-09-09 18:57 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: stefaandr at hotmail dot com @ 2003-09-09 17:53 UTC (permalink / raw)
  To: gcc-bugs

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



------- Additional Comments From stefaandr at hotmail dot com  2003-09-09 17:53 -------
Appearantly, if I do a specialized initialization
  template <> b a<float>::b1 = b();
and a templated one
  template <class T> b a<T>::b1 = b();
over different object files, the result of the linking is that the same object
(same this pointer) is initialized twice (seen by std-outing something inside
the constructor).  Is this a bug in the linker or the compiler?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/12222] explicit initialization of static template members seems ignored
  2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
@ 2003-09-09 14:08 ` bangerth at dealii dot org
  2003-09-09 17:53 ` stefaandr at hotmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2003-09-09 14:08 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-01  3:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-12222-4@http.gcc.gnu.org/bugzilla/>
2012-02-01  3:07 ` [Bug c++/12222] explicit initialization of static template members seems ignored pinskia at gcc dot gnu.org
2003-09-09 10:16 [Bug c++/12222] New: " stefaandr at hotmail dot com
2003-09-09 14:08 ` [Bug c++/12222] " bangerth at dealii dot org
2003-09-09 17:53 ` stefaandr at hotmail dot com
2003-09-09 18:57 ` bangerth at dealii dot org
2003-12-26 23:36 ` pinskia at gcc dot gnu dot org
2004-08-16 18:37 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).