@@ -6934,15 +6934,23 @@ pop_init_level (int implicit, struct obstack * braced_init_obstack)
&& TREE_CODE (constructor_type) == RECORD_TYPE
&& constructor_unfilled_fields)
{
+ bool constructor_zeroinit =
+ (VEC_length (constructor_elt, constructor_elements) == 1
+ && integer_zerop
+ (VEC_index (constructor_elt, constructor_elements, 0)->value));
+
/* Do not warn for flexible array members or zero-length arrays. */
while (constructor_unfilled_fields
&& (!DECL_SIZE (constructor_unfilled_fields)
|| integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
- /* Do not warn if this level of the initializer uses member
- designators; it is likely to be deliberate. */
- if (constructor_unfilled_fields && !constructor_designated)
+ if (constructor_unfilled_fields
+ /* 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}'. */
+ && !constructor_zeroinit)
{
push_member_name (constructor_unfilled_fields);
warning_init (OPT_Wmissing_field_initializers,
@@ -9,3 +9,6 @@ struct s s4[] = { 1, 2, 3, 4, 5 }; /* { dg-warning "(missing initializer)|(near
struct s s5[] = { 1, 2, 3, 4, 5, 6 };
/* Designated initializers produce no warning. */
struct s s6 = { .a = 1 }; /* { dg-bogus "missing initializer" } */
+/* Allow zero-initializing with "= { 0 }". */
+struct s s7 = { 0 }; /* { dg-bogus "missing initializer" } */
+struct s s8 = { 1 }; /* { dg-warning "(missing initializer)|(near initialization)" } */