diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2023-02-01 20:34:11 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2023-02-01 20:34:11 +0000 |
commit | 461a7552b676e4b3aa94480b628e8a3776759fff (patch) | |
tree | 557cf600588f545a86df3734b28c035fc9c880a2 /gnu | |
parent | 4f946afaecbc214510d5b6317131f537dbb7c073 (diff) |
Backport gnu/gcc/gcc/c-typeck.c r1.3 to the gcc 3 code base:
Adjust how gcc3 handles the "missing braces around initializer" warning.
In c99 any value can be initalised using a { 0 } constructor independent
of the type. Now if a struct's first member is another struct then gcc4
issues the above warning but it should not do that.
Move the warning check from push_init_level() to pop_init_level() and
check if either { 0 } or { } was used. If additional implicit braces
were added surpress the warning.
Inspired by gcc PR#64709
light testing by me, serious testing by aoyama@
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 |