Description
For each explicitly initialized element:
- If the element is an anonymous union member and the initializer list is a brace-enclosed designated-initializer-list, the element is initialized by the designated-initializer-list { D }, where D is the designated-initializer-clause naming a member of the anonymous union member. There shall be only one such designated-initializer-clause.
How could designated-initializer-list be the form { D }
? According to the grammar of designated-initializer-list, it should be the comma-separated list of .identifier brace-or-equal-initializer. The above rule seems to phrase the following example
struct C{
union {
int a;
};
};
C c = {{.a = 0}};
In this example, the corresponding initializer of the anonymous union member is the initializer-clasuse
, which is a brace-enclosed designated-initializer-list. However, the formal example under [dcl.init.aggr]/4.1 is that
struct C {
union {
int a;
const char* p;
};
int x;
} c = { .a = 1, .x = 3 };
That is, the original intent of the above rule is used to phrase the case where the explicitly initialized element is an anonymous union member and the corresponding initializer is a designated-initializer-clause naming the member of it. Should we reword the rule to that
If the element is an anonymous union member and the initializer D is a designated-initializer-clause naming a member of the anonymous union member, the element is initialized by the initializer { D }. There shall be only one such designated-initializer-clause for the anonymous union member.
Activity