summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-29 21:02:21 +0000
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-29 21:02:21 +0000
commit70279be92f789310f7f2a9aa6df4f2ae9920d4b5 (patch)
tree11ab17e0248f5e7538c9d5b630dba979f09c58b6
parent72d590fcb895b5bec3c61dc6a437f69f24a78467 (diff)
downloadgcc-70279be92f789310f7f2a9aa6df4f2ae9920d4b5.tar.gz
PR c/64709
* c-typeck.c (pop_init_level): If constructor_elements has exactly one element with integer_zerop value, set constructor_zeroinit to 1. Remove braces around warning_init call. * gcc.dg/pr64709.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220263 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-typeck.c28
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr64709.c10
4 files changed, 40 insertions, 10 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 408fc163ab7..7c2ce3865e8 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-29 Marek Polacek <polacek@redhat.com>
+
+ PR c/64709
+ * c-typeck.c (pop_init_level): If constructor_elements has
+ exactly one element with integer_zerop value, set constructor_zeroinit
+ to 1. Remove braces around warning_init call.
+
2015-01-27 Jakub Jelinek <jakub@redhat.com>
PR c/64766
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index aa74968d28b..65c6f7f4272 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -7557,20 +7557,28 @@ pop_init_level (location_t loc, int implicit,
}
}
- /* Initialization with { } counts as zeroinit. */
- if (vec_safe_length (constructor_elements) == 0)
- constructor_zeroinit = 1;
- /* If the constructor has more than one element, it can't be { 0 }. */
- else if (vec_safe_length (constructor_elements) != 1)
- constructor_zeroinit = 0;
+ switch (vec_safe_length (constructor_elements))
+ {
+ case 0:
+ /* Initialization with { } counts as zeroinit. */
+ constructor_zeroinit = 1;
+ break;
+ case 1:
+ /* This might be zeroinit as well. */
+ if (integer_zerop ((*constructor_elements)[0].value))
+ constructor_zeroinit = 1;
+ break;
+ default:
+ /* If the constructor has more than one element, it can't be { 0 }. */
+ constructor_zeroinit = 0;
+ break;
+ }
/* Warn when some structs are initialized with direct aggregation. */
if (!implicit && found_missing_braces && warn_missing_braces
&& !constructor_zeroinit)
- {
- warning_init (loc, OPT_Wmissing_braces,
- "missing braces around initializer");
- }
+ warning_init (loc, OPT_Wmissing_braces,
+ "missing braces around initializer");
/* Warn when some struct elements are implicitly initialized to zero. */
if (warn_missing_field_initializers
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d3b38839083..f46ea72cfac 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-29 Marek Polacek <polacek@redhat.com>
+
+ PR c/64709
+ * gcc.dg/pr64709.c: New test.
+
2015-01-29 Jakub Jelinek <jakub@redhat.com>
PR c++/64717
diff --git a/gcc/testsuite/gcc.dg/pr64709.c b/gcc/testsuite/gcc.dg/pr64709.c
new file mode 100644
index 00000000000..337e3db3e17
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr64709.c
@@ -0,0 +1,10 @@
+/* PR c/64709 */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-field-initializers" } */
+
+struct S { int a, b; };
+void
+foo (void)
+{
+ struct S s[] = { { 1, 2 }, { 0 } }; /* { dg-bogus "missing initializer for field" } */
+}