[Bug c++/19123] New: Static member object gets constructed after containing objects constructor returns
lenkki at atria dot no-ip dot org
gcc-bugzilla@gcc.gnu.org
Wed Dec 22 00:20:00 GMT 2004
I'm not 100% if this is a bug or if the standard is undefined on this point.
But I do believe it is a bug, or atleast unwanted behaviour.
As I don't see where to insert a archive with the files and data I've gathered
on bugzilla I'm leaving them on my http viewable from your browser.
http://atria.no-ip.org/gcc-bug/
There is some info in the README file (build line etc). And the output of gcc
save temps is in :
http://atria.no-ip.org/gcc-bug/gcc-save-temps-output
The code is extracted and trimmed down from my program to contain only the code
neccesary to trigger it.
C_CHILD has two constructors one that takes no arguments and one that takes a
const char*,
C_ROOT has a static member of type C_CHILD, that is constructed with a string
constant.
cCore has a static member of type C_ROOT that uses the standard ctor.
cCore is not instanced anywhere (but it was in my code, apparently not needed to
trigger it).
Now the problem is. The C_ROOT member of cCore is constructed, The default
constructor is ran. Then after the constructor has returned C_ROOT's static
member is constructed using the constructor specified in the static declaration.
By all means I think and I assumed that all members of a class would be
constructed before the constructor of the containing class was run, and not after.
I've had a few friends test this too, on MSVC++ it produces the expected
results (child constructed first) and on
g++ (GCC) 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice) it also produces
the expected result.
--
Summary: Static member object gets constructed after containing
objects constructor returns
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lenkki at atria dot no-ip dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19123
More information about the Gcc-bugs
mailing list