std::array
initialization is still not permissive enoughSection: 23.3.3.1 [array.overview] Status: Open Submitter: Robert Haberlach Opened: 2016-11-16 Last modified: 2018-03-19
Priority: 3
View other active issues in [array.overview].
View all other issues in [array.overview].
View all issues with Open status.
Discussion:
LWG 2590's resolution is incomplete:
std::array<int, 1> arr{{0}};
should be fine, but isn't guaranteed, since {0}
has no type. We should rather go for implicit conversion:
An array is an aggregate (9.4.2 [dcl.init.aggr]) that can be list-initialized with up to
N
elementswhose types are convertible tothat can be implicitly converted toT
T
.
[2016-11-26, Tim Song comments]
This is not possible as written, because due to the brace elision rules for aggregate initialization,
std::array<int, 2> arr{{0}, {1}};
will never work: the {0}
is taken as initializing the inner array, and the {1}
causes an error.
[2017-01-27 Telecon]
Priority 2; consensus is that the P/R is not quite right.
[2018-3-14 Wednesday evening issues processing; priority to 3; move to Open]
Jens: There's nothing you can do about the double braces in std::array. That's a core thing.
STL to write paper to resolve this.
Proposed resolution:
This wording is relative to N4606.
Change 23.3.3.1 [array.overview] p2 as indicated:
-2- An
array
is an aggregate (9.4.2 [dcl.init.aggr]) that can be list-initialized with up toN
elementswhose types are convertiblethat can be implicitly converted toT
.