Compiling this with -Wmissing-field-initializers evokes a warning:
struct foo { int a; int b; };
struct foo f = { 1 };
but with "designated initializers" it does not:
struct foo { int a; int b; };
struct foo f = { .a = 1 };
That -Wmissing-field-initializers works this way is even documented.
My quandary is that I'd prefer to use the more readable and
maintainable c99 form, especially with long lists of member names:
foo = {
.f1 = callback_a,
.f2 = callback_b,
.f3 = callback_c,
...
.fn = callback_n,
};
Then, it's obvious that foo.f23 is initialized to callback_23,
whereas with old-style initializations, I'd have to count,
and if ever I had the misfortune to reorder member names,
and signatures are similar, it'd be easy to miss the error.
However, the old-style initialization has the advantage that
when I add a new member, gcc -Wmissing-field-initializers will
prompt me to add a new initializer. With the c99-style, there
seems to be no way to evoke a similar prod.
Maybe we can get the best of both worlds?
Paolo Bonzini mentioned that this would be easy to implement,
and that -Wmissing-field-initializers=2 may be the way to do it,
given the precedent of -Wstrict-overflow and -Wstrict-overflow=<N>.
--
Summary: make -Wmissing-field-initializers=2 work with
"designated initializers" ?
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jim at meyering dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39589