Is aggregate member copy-initialization associated with the corresponding initializer-clause?

3 views
Skip to first unread message

Edward Catmur

unread,
Feb 25, 2015, 5:34:30 AM2/25/15
to std-dis...@isocpp.org
From http://stackoverflow.com/q/21294831/567292:

struct S { int i; int j; };
int f() { S s{5, s.i}; return s.j; }

Is this defined behavior
, or does s.i have indeterminate value at the point of access?

[dcl.init.aggr]/2 has:
When an aggregate is initialized by an initializer list, as specified in 8.5.4, the elements of the initializer list
are taken as initializers for the members of the aggregate, in increasing subscript or member order. Each
member is copy-initialized from the corresponding initializer-clause.

[dcl.init.list]/4 has:
Within the initializer-list of a braced-init-list, the initializer-clauses, including any that result from pack
expansions (14.5.3), are evaluated in the order in which they appear. That is, every value computation and
side effect associated with a given initializer-clause is sequenced before every value computation and side
effect associated with any initializer-clause that follows it in the comma-separated list of the initializer-list.

The copy-initialization of an aggregate member is certainly a side effect ([intro.execution]/12), but is it "associated with" the corresponding initializer-clause or is that only intended to cover modifications to other objects, as S s{++i, ++i}?

The alternative would be that the copy-initialization of aggregate members is associated with the full-expression of the initialization; this could e.g. be more efficient where it is possible to initialize multiple aggregate members en bloc.
Reply all
Reply to author
Forward
0 new messages