Is it wise to ignore gcc/clang’s “-Wmissing-braces” warning?

-Wmissing-braces will no longer be enabled in GCC’s -Wall (for C++ mode), as of 4.8, for precisely the reason you describe. For current versions of GCC, either disable or ignore the warning, the code you have is written the way it should be.

The warning is probably meant to cover code such as

struct A { int a; int b; };
struct B { A a; int b; };
B b = {
  2 // initialises b.a.b, not b.b

However, IMHO, that is already handled well enough by -Wmissing-field-initializers, which does not warn about your original code.

Leave a Comment