PR63480 points out that -Wmissing-field-initializers warns about initializing with { }. Given that we suppress the warning for initializing with { 0 }, I think it makes sense to suppress it for { } as well. (Initializing with { } is a GNU extension and -pedantic warns on that.)
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-10-08 Marek Polacek <pola...@redhat.com> PR c/63480 * c-typeck.c (pop_init_level): Don't warn about initializing with { }. * gcc.dg/pr63480.c: New test. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index b3b82bb..5c0697a 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -7436,7 +7436,11 @@ pop_init_level (location_t loc, int implicit, } } - if (vec_safe_length (constructor_elements) != 1) + /* Initialization with { } counts as zeroinit. */ + if (vec_safe_length (constructor_elements) == 0) + constructor_zeroinit = 1; + /* If the constructor has more than one element, it can't be { 0 }. */ + else if (vec_safe_length (constructor_elements) != 1) constructor_zeroinit = 0; /* Warn when some structs are initialized with direct aggregation. */ @@ -7463,7 +7467,7 @@ pop_init_level (location_t loc, int implicit, /* Do not warn if this level of the initializer uses member designators; it is likely to be deliberate. */ && !constructor_designated - /* Do not warn about initializing with ` = {0}'. */ + /* Do not warn about initializing with { 0 } or with { }. */ && !constructor_zeroinit) { if (warning_at (input_location, OPT_Wmissing_field_initializers, diff --git gcc/testsuite/gcc.dg/pr63480.c gcc/testsuite/gcc.dg/pr63480.c index e69de29..89e2586 100644 --- gcc/testsuite/gcc.dg/pr63480.c +++ gcc/testsuite/gcc.dg/pr63480.c @@ -0,0 +1,14 @@ +/* PR c/63480 */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-field-initializers" } */ + +/* Test that we don't warn about initializing with { }. */ + +struct S { int a, b, c; } s = { }; + +void +foo (void) +{ + struct S s = { }; + struct S s2 = (struct S){ }; +} Marek