diff options
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/gcc/gcc/c-typeck.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/gnu/usr.bin/gcc/gcc/c-typeck.c b/gnu/usr.bin/gcc/gcc/c-typeck.c index e574845e4d5..78342f51f89 100644 --- a/gnu/usr.bin/gcc/gcc/c-typeck.c +++ b/gnu/usr.bin/gcc/gcc/c-typeck.c @@ -4945,6 +4945,9 @@ static int constructor_erroneous; /* 1 if have called defer_addressed_constants. */ static int constructor_subconstants_deferred; +/* 1 if this constructor is a zero init. */ +static int constructor_zeroinit; + /* Structure for managing pending initializer elements, organized as an AVL tree. */ @@ -5403,12 +5406,6 @@ push_init_level (implicit) set_nonincremental_init (); } - if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned) - { - missing_braces_mentioned = 1; - warning_init ("missing braces around initializer"); - } - if (TREE_CODE (constructor_type) == RECORD_TYPE || TREE_CODE (constructor_type) == UNION_TYPE) { @@ -5534,6 +5531,24 @@ pop_init_level (implicit) abort (); } + if (constructor_elements == 0) + constructor_zeroinit = 1; + else if (TREE_CHAIN (constructor_elements) == 0 && + initializer_zerop (TREE_VALUE (constructor_elements))) + { + constructor_zeroinit = 1; + } + else + constructor_zeroinit = 0; + + /* only warn for missing braces unless it is { 0 } */ + if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned && + !constructor_zeroinit) + { + missing_braces_mentioned = 1; + warning_init ("missing braces around initializer"); + } + /* Warn when some struct elements are implicitly initialized to zero. */ if (extra_warnings && constructor_type |