1 Fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
2 wrong warning when using the universal zero initializer {0}
4 Backported to GCC 4.8.3
6 Subject: 2014-06-05 S. Gilles <sgilles@terpmail.umd.edu>
7 X-Git-Url: http://repo.or.cz/w/official-gcc.git/commitdiff_plain/95cdf3fdf2d440eb7775def8e35ab970651c33d9?hp=14a3093e9943937cbc63dfbf4d51ca60f8325b29
8 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211289 138bc75d-0d04-0410-961f-82ee72b054a4
10 --- gcc-4.8.3.org/gcc/c/c-typeck.c 2014-08-03 20:52:09.257042137 +0200
11 +++ gcc-4.8.3/gcc/c/c-typeck.c 2014-08-03 20:57:10.645042614 +0200
13 if expr.original_code == SIZEOF_EXPR. */
14 tree c_last_sizeof_arg;
16 -/* Nonzero if we've already printed a "missing braces around initializer"
17 - message within this initializer. */
18 -static int missing_braces_mentioned;
19 +/* Nonzero if we might need to print a "missing braces around
20 + initializer" message within this initializer. */
21 +static int found_missing_braces;
23 static int require_constant_value;
24 static int require_constant_elements;
26 /* 1 if this constructor is erroneous so far. */
27 static int constructor_erroneous;
29 +/* 1 if this constructor is the universal zero initializer { 0 }. */
30 +static int constructor_zeroinit;
32 /* Structure for managing pending initializer elements, organized as an
36 constructor_stack = 0;
37 constructor_range_stack = 0;
39 - missing_braces_mentioned = 0;
40 + found_missing_braces = 0;
45 constructor_type = type;
46 constructor_incremental = 1;
47 constructor_designated = 0;
48 + constructor_zeroinit = 1;
50 designator_erroneous = 0;
52 @@ -6832,11 +6836,8 @@
53 set_nonincremental_init (braced_init_obstack);
56 - if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
58 - missing_braces_mentioned = 1;
59 - warning_init (OPT_Wmissing_braces, "missing braces around initializer");
62 + found_missing_braces = 1;
64 if (TREE_CODE (constructor_type) == RECORD_TYPE
65 || TREE_CODE (constructor_type) == UNION_TYPE)
66 @@ -6969,16 +6970,23 @@
70 + if (vec_safe_length (constructor_elements) != 1)
71 + constructor_zeroinit = 0;
73 + /* Warn when some structs are initialized with direct aggregation. */
74 + if (!implicit && found_missing_braces && warn_missing_braces
75 + && !constructor_zeroinit)
77 + warning_init (OPT_Wmissing_braces,
78 + "missing braces around initializer");
81 /* Warn when some struct elements are implicitly initialized to zero. */
82 if (warn_missing_field_initializers
84 && TREE_CODE (constructor_type) == RECORD_TYPE
85 && constructor_unfilled_fields)
87 - bool constructor_zeroinit =
88 - (vec_safe_length (constructor_elements) == 1
89 - && integer_zerop ((*constructor_elements)[0].value));
91 /* Do not warn for flexible array members or zero-length arrays. */
92 while (constructor_unfilled_fields
93 && (!DECL_SIZE (constructor_unfilled_fields)
96 designator_erroneous = 0;
98 + if (!implicit && value.value && !integer_zerop (value.value))
99 + constructor_zeroinit = 0;
101 /* Handle superfluous braces around string cst as in
102 char x[] = {"foo"}; */