This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Bug c++/43330] New: trivial types are not being statically initialized




Sent from my iPhone

On Mar 11, 2010, at 3:24 AM, "eric dot niebler at gmail dot com" <gcc-bugzilla@gcc.gnu.org > wrote:

According to the C++0x status page
(http://gcc.gnu.org/gcc-4.5/cxx0x_status.html), "Standard Layout Types"
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2342.htm) have been
implemented in gcc-4.5. A quick test shows that trivial types are not being
statically initialized, as the paper requires. The following struct S is
trivial and the non-local constant s should be statically initialized, IIUC:


 struct S
 {
   S() {}
 };

The above is not a trivial type though. It has a non trivial default constructor. If you want a trivial constructor use either "= default" or delete it all together.




S const s{};


However, when compiled with -O2 -std=c++0x -S using the latest 4.5 snapshot, I
see the following assembly:


.file "main.cpp"
.text
.p2align 4,,15
.def __GLOBAL__I_main.cpp; .scl 3; .type 32; .endef
__GLOBAL__I_main.cpp:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
.section .ctors,"w"
.align 4
.long __GLOBAL__I_main.cpp


Unless I'm mistaken, the global s is still being dynamically initialized.
Apologies in advance if I'm reading this wrong.



-- Summary: trivial types are not being statically initialized Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: eric dot niebler at gmail dot com GCC build triplet: gcc-4.5-20100304


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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]