https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123013

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2025-12-05

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to nvinson234 from comment #0)
> I also see the same warning if I replace `.b = 4,` with `.b = {4}`.

Yes, because that just puts redundant braces around the initializer for an int,
it doesn't put braces around the initializer for the union, which is what the
warning is about.

That's equivalent to just doing this at block scope:  int i = {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
> `

That only happens for C++20 mode, the GCC extension in C++17 mode doesn't give
an error. But I think GCC is correct that the very restrictive rules for
designated init in C++20 don't allow it.


> 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.

Yes, it's wrong to suggest there should be braces there when designated init is
being used.

Reply via email to