Title
Value initialization of arrays of POD-structs
Status
cd2
Section
11.9 [class.init]
Submitter
Alisdair Meredith

Created on 2005-10-27.00:00:00 last changed 143 months ago

Messages

Date: 2009-03-15.00:00:00

[Voted into the WP at the March, 2009 meeting.]

Date: 2006-10-15.00:00:00

Proposed resolution (October, 2006):

Change 11.9 [class.init] paragraph 3 as follows:

When an array of class objects is initialized (either explicitly or implicitly) and the elements are initialized by constructor, the constructor shall be called for each element of the array, following the subscript order; see 9.3.4.5 [dcl.array].
Date: 2005-10-27.00:00:00

11.9 [class.init] paragraph 2 says,

When an array of class objects is initialized (either explicitly or implicitly), the constructor shall be called for each element of the array, following the subscript order;

That implies that, given

    struct POD {
      int x;
    };

    POD data[10] = {};

this should call the implicitly declared default ctor 10 times, leaving 10 uninitialized ints, rather than value initialize each member of data, resulting in 10 initialized ints (which is required by 9.4.2 [dcl.init.aggr] paragraph 7).

I suggest rephrasing along the lines:

When an array is initialized (either explicitly or implicitly), each element of the array shall be initialized in turn, following the subscript order;

This would allow for PODs and other classes with a dual nature under value/default initialization, and cover copy initialization for arrays too.

History
Date User Action Args
2010-03-29 00:00:00adminsetstatus: wp -> cd2
2009-08-03 00:00:00adminsetstatus: dr -> wp
2009-03-23 00:00:00adminsetmessages: + msg2028
2009-03-23 00:00:00adminsetstatus: ready -> dr
2008-10-05 00:00:00adminsetstatus: review -> ready
2006-11-05 00:00:00adminsetmessages: + msg1407
2006-11-05 00:00:00adminsetstatus: drafting -> review
2006-04-22 00:00:00adminsetstatus: open -> drafting
2005-10-27 00:00:00admincreate