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

2010-03-11 Thread pinskia at gmail dot com


--- 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-bugzi...@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;   .scl3;  .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



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

2010-03-11 Thread eric dot niebler at gmail dot com


--- 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



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

2010-03-11 Thread eric dot niebler at gmail dot com


--- 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