From: Alexander Monakov Date: Fri, 22 Apr 2011 11:53:01 +0000 (+0400) Subject: re PR c/36750 (-Wmissing-field-initializers relaxation request) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=49819fef626b1757ad21c03f0695e68388fdb42d;p=gcc.git re PR c/36750 (-Wmissing-field-initializers relaxation request) PR c/36750 * c-typeck.c (pop_init_level): Do not warn about initializing with ` = {0}'. testsuite: * gcc.dg/missing-field-init-2.c: Update testcase. From-SVN: r172857 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ec3b8d1ba8b..2401fd2fee5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-04-22 Alexander Monakov + + PR c/36750 + * c-typeck.c (pop_init_level): Do not warn about initializing + with ` = {0}'. + 2011-04-22 Alan Modra * config/rs6000/rs6000.c (rs6000_function_arg): Remove CALL_LIBCALL diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 15b77550dc3..d8609d24e3f 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da59b77a5db..95618277add 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-04-22 Alexander Monakov + + PR c/36750 + * gcc.dg/missing-field-init-2.c: Update testcase. + 2011-04-22 Alan Modra * gcc.target/powerpc/ppc-pow.c: Allow for tail calls. diff --git a/gcc/testsuite/gcc.dg/missing-field-init-2.c b/gcc/testsuite/gcc.dg/missing-field-init-2.c index 581eb30d89b..c5a3f490387 100644 --- a/gcc/testsuite/gcc.dg/missing-field-init-2.c +++ b/gcc/testsuite/gcc.dg/missing-field-init-2.c @@ -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)" } */