public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13406] New: initialisation of instantiated static data member not correct
@ 2003-12-15 23:50 o dot kullmann at swansea dot ac dot uk
2003-12-16 8:28 ` [Bug c++/13406] " bangerth at dealii dot org
2003-12-28 3:26 ` pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: o dot kullmann at swansea dot ac dot uk @ 2003-12-15 23:50 UTC (permalink / raw)
To: gcc-bugs
#include <iostream>
#include <ostream>
struct L {
std::ostream& s;
L() : s(std::cout) {}
};
template <class T>
struct S {
static L l;
S() { l.s << ""; }
};
template <class T>
L S<T>::l;
struct X : S<X> {};
X x_global;
int main() {};
-----------------------
This program compiles, and when run, yields a memory error.
However, it should be well-formed and should run without error.
The error disappears when explicitely instantiating the static
data member l of the instantiated class S<X>.
Section 14.7.1 of the standard says that
"in particular, the initialization (and any associated side-effects) of a
static data member does not occur unless the static data member is itself used
in a way that requires the definition of the static data member to exist.",
and thus l should have been initialised before it is used in the body of the
constructor of class S<X> (this is where the error occurs).
--
Summary: initialisation of instantiated static data member not
correct
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: o dot kullmann at swansea dot ac dot uk
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13406
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/13406] initialisation of instantiated static data member not correct
2003-12-15 23:50 [Bug c++/13406] New: initialisation of instantiated static data member not correct o dot kullmann at swansea dot ac dot uk
@ 2003-12-16 8:28 ` bangerth at dealii dot org
2003-12-28 3:26 ` pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2003-12-16 8:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2003-12-16 08:02 -------
The program crashes because you attempt to use std::cout in the
initialization code of your global variable x_global which seems to run before
the initialization code of the global variable std::cout is run.
I would assume that the standard doesn't say much about which
variable is to be initialized first, no?
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13406
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/13406] initialisation of instantiated static data member not correct
2003-12-15 23:50 [Bug c++/13406] New: initialisation of instantiated static data member not correct o dot kullmann at swansea dot ac dot uk
2003-12-16 8:28 ` [Bug c++/13406] " bangerth at dealii dot org
@ 2003-12-28 3:26 ` pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-28 3:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-28 03:10 -------
Yes the standard does not say which variable is initialized first, there is another bug
about that. Closing as this is invalid code.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13406
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-12-28 3:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-15 23:50 [Bug c++/13406] New: initialisation of instantiated static data member not correct o dot kullmann at swansea dot ac dot uk
2003-12-16 8:28 ` [Bug c++/13406] " bangerth at dealii dot org
2003-12-28 3:26 ` pinskia at gcc dot gnu 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).