public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43330] New: trivial types are not being statically initialized
@ 2010-03-11 11:24 eric dot niebler at gmail dot com
2010-03-11 11:41 ` Andrew Pinski
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: eric dot niebler at gmail dot com @ 2010-03-11 11:24 UTC (permalink / raw)
To: gcc-bugs
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() {}
};
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Bug c++/43330] New: trivial types are not being statically initialized
2010-03-11 11:24 [Bug c++/43330] New: trivial types are not being statically initialized eric dot niebler at gmail dot com
@ 2010-03-11 11:41 ` Andrew Pinski
2010-03-11 11:42 ` [Bug c++/43330] " pinskia at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2010-03-11 11:41 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/43330] trivial types are not being statically initialized
2010-03-11 11:24 [Bug c++/43330] New: trivial types are not being statically initialized eric dot niebler at gmail dot com
2010-03-11 11:41 ` Andrew Pinski
@ 2010-03-11 11:42 ` pinskia at gmail dot com
2010-03-11 11:54 ` eric dot niebler at gmail dot com
2010-03-11 11:56 ` eric dot niebler at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gmail dot com @ 2010-03-11 11:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gmail dot com 2010-03-11 11:41 -------
Subject: Re: 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
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/43330] trivial types are not being statically initialized
2010-03-11 11:24 [Bug c++/43330] New: trivial types are not being statically initialized eric dot niebler at gmail dot com
2010-03-11 11:41 ` Andrew Pinski
2010-03-11 11:42 ` [Bug c++/43330] " pinskia at gmail dot com
@ 2010-03-11 11:54 ` eric dot niebler at gmail dot com
2010-03-11 11:56 ` eric dot niebler at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: eric dot niebler at gmail dot com @ 2010-03-11 11:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from eric dot niebler at gmail dot com 2010-03-11 11:53 -------
You're right. Let me amend my example.
struct S
{
S() = default;
S(S const &) = default;
S(int i) : i(i) {}
int i;
};
S const s {1};
S would seem to satisfy the requirements for a trivial type now, correct? N2342
states:
"When an aggregate with static storage duration is initialized with a
brace-enclosed initializer-list, if all the member initializer expressions are
constant expressions, and the aggregate is a trivial type, the initialization
shall be done during the static phase of initialization"
GCC initializes s dynamically. That doesn't seem right. I see that constant
expressions are not yet implemented in gcc-4.5. Am I correct in assuming that
once constant expressions are implemented, this initialization will be static?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/43330] trivial types are not being statically initialized
2010-03-11 11:24 [Bug c++/43330] New: trivial types are not being statically initialized eric dot niebler at gmail dot com
` (2 preceding siblings ...)
2010-03-11 11:54 ` eric dot niebler at gmail dot com
@ 2010-03-11 11:56 ` eric dot niebler at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: eric dot niebler at gmail dot com @ 2010-03-11 11:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from eric dot niebler at gmail dot com 2010-03-11 11:56 -------
Oops, it's not an aggregate. Disregard.
--
eric dot niebler at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43330
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-03-11 11:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 11:24 [Bug c++/43330] New: trivial types are not being statically initialized eric dot niebler at gmail dot com
2010-03-11 11:41 ` Andrew Pinski
2010-03-11 11:42 ` [Bug c++/43330] " pinskia at gmail dot com
2010-03-11 11:54 ` eric dot niebler at gmail dot com
2010-03-11 11:56 ` eric dot niebler at gmail dot com
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).