-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter (unless configured in github; will be published with the issue): Tam S. B.
Reference (section label): [dcl.init.aggr]
Link to reflector thread (if any):
Issue description:
Consider:
union A {
const char* x;
int y;
};
struct B {
A a;
int t;
};
B b = {nullptr, 1};
Otherwise, the aggregate element is an aggregate and that subaggregate is replaced in the list of aggregate elements by the sequence of its own aggregate elements, and the appertainment analysis resumes with the first such element and the same
initializer-clause
.
Per [dcl.init.aggr]/14, to determine the appertainment of each initializer-clause in B b = {nullptr, 1}
, the sequence {nullptr
, 1
} is compared with the list of aggregate elements {B::a
, B::t
}. Since nullptr
cannot appertain to B::a
of type A
, the latter is replaced by A
's list of aggregate elements, turning the list to {A::x
, A::y
, B::t
}. This renders the initialization equivalent to B b = {.a = {.x = nullptr, .y = 1}}
, which is ill-formed per [dcl.init.aggr]/20.
I believe that this initialization should be well-formed and equivalent to B b = {.a = {.x = nullptr}, .t = 1};
.
Suggested resolution:
Modify [dcl.init.aggr]/14 as indicated:
Otherwise, the aggregate element is an aggregate and that subaggregate is replaced in the list of aggregate elements by the sequence of its own aggregate elements if it is not an union, and by its first aggregate element otherwise.
, and tThe appertainment analysis resumes with the first such element and the sameinitializer-clause
.