https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128838
Bug ID: 128838
Summary: Brace elision is rejected in designated initializer
for wrapped array in subobject of aggregate
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: friedkeenan at protonmail dot com
Target Milestone: ---
The following code is rejected:
```
struct DoubleInt {
int elems[2];
};
struct Inner {
DoubleInt ints;
};
struct Outer {
Inner inner;
};
int main() {
auto _ = Outer({
.ints = {1, 2}
});
}
```
Godbolt link: https://godbolt.org/z/87T7r1rGM
The code is accepted if one initializes `ints` with double braces like `{{1,
2}}`. It's also accepted if one replaces `Outer(...)` with Outer{...}`, using
braces instead of parentheses.
The error does not occur if DoubleInt holds two separate data members, nor if
one uses a designated initializer for `inner` like
```
auto _ = Outer{.inner = {
.ints = {1, 2}
}};
```
It can also be resolved by adding a constructor to Outer which just does
```
Outer(Inner inner) : inner(inner) {}
```
I initially ran into this issue with std::array, which acts equivalently to
DoubleInt here. My code was also using inheritance, like if Outer were defined
like
```
struct Outer : Inner {};
```
Where a designated initializer for the inner object cannot be specified.
Skimming through the compiler versions on compiler explorer would seem to show
that this has always been a bug.