https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123013
Bug ID: 123013
Summary: -Wmissing-braces emits warning when using designated
initializer and anonymous union
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nvinson234 at gmail dot com
Target Milestone: ---
Given the following code:
```
#include <cstdio>
struct test {
int a;
union {
int b;
int c;
};
int d;
};
int main() {
struct test t = {
.a = 3,
.b = 4,
.d = 5,
};
printf("%d %d %d\n", t.a, t.b, t.d);
return 0;
}
```
compiling it with gcc-trunk using the following command:
g++ -Wmissing-braces test.cc
I get the warning:
```
test.cc: In function ‘int main()’:
test.cc:17:5: warning: missing braces around initializer for ‘test::<unnamed
union>’ [-Wmissing-braces]
17 | };
| ^
```
I also see the same warning if I replace `.b = 4,` with `.b = {4}`.
If I replace `.b = 4,` with `{ .b = 4 },` I get the error `test.cc:15:9: error:
either all initializer clauses should be designated or none of them should be
`
Therefore, it appears that the warning is incorrect as there's no way to alter
the source code to suppress it *and* use designated initializers.
compiler version:
```
g++ (Gentoo 16.0.9999 p, commit c4bca4ffea4fdc0b1a5f9a9d05727da1181ce0b6)
16.0.0 20251203 (experimental) 4a1247a3b070cdb02910826a5effb505457a6e73
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```