Created on 2008-05-14.00:00:00 last changed 130 months ago
[Voted into the WP at the November, 2010 meeting.]
Proposed resolution (October, 2010):
Change 9.4 [dcl.init] paragraph 5 as follows:
To zero-initialize an object or reference of type T means:
if T is a scalar type (6.8 [basic.types]), the object is set to the value 0 (zero), taken as an integral constant expression, converted to T;103
if T is a (possibly cv-qualified) non-union class type, each non-static data member and each base-class subobject is zero-initialized, and padding is initialized to zero bits;
if T is a (possibly cv-qualified) union type, the object's first non-static named data member is zero-initialized, and padding is initialized to zero bits;
if T is an array type, each element is zero-initialized;
if T is a reference type, no initialization is performed.
Additional notes (February, 2010):
The C Committee has changed its approach to this question and is no longer using a two-phase process; in C, zero-initialization is specific to program start-up and thus is not appropriate for use with thread-local storage. See C paper N1387.
Notes from the September, 2008 meeting:
It was observed that padding bytes in structs are zero-initialized in C, so if we are changing the treatment of unions in this way we should consider adding the C behavior for padding bytes at the same time. In particular, using memcmp to compare structs only works reliably if the padding bytes are zero-initialized.
Proposed resolution (August, 2008):
Change bullet 3 of 9.4 [dcl.init] paragraph 5 (in the first list, dealing with zero-initialization) as follows:
[Drafting notes: Ask a C liaison about the progress of WG14 paper N1311, which deals with this issue. Since the adoption of WG21 paper N2544, unions may have static data members, hence the change to refer to the first non-static data member and the deletion of the footnote.]
The C committee is considering changing the definition of zero-initialization of unions to guarantee that the bytes of the entire union are set to zero before assigning 0, converted to the appropriate type, to the first member. The argument (summarized here) is for backward compatibility. The C++ Committee may want to consider the same change.
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-03-03 00:00:00 | admin | set | status: fdis -> c++11 |
2011-04-10 00:00:00 | admin | set | status: dr -> fdis |
2010-11-29 00:00:00 | admin | set | messages: + msg3176 |
2010-11-29 00:00:00 | admin | set | status: tentatively ready -> dr |
2010-10-18 00:00:00 | admin | set | messages: + msg2984 |
2010-10-18 00:00:00 | admin | set | status: drafting -> tentatively ready |
2010-02-16 00:00:00 | admin | set | messages: + msg2572 |
2009-11-08 00:00:00 | admin | set | status: review -> drafting |
2008-10-05 00:00:00 | admin | set | messages: + msg1766 |
2008-08-25 00:00:00 | admin | set | messages: + msg1751 |
2008-08-25 00:00:00 | admin | set | status: open -> review |
2008-05-14 00:00:00 | admin | create |