]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/59351 (ICE on empty compound literal with -pedantic)
authorMarek Polacek <polacek@redhat.com>
Tue, 3 Dec 2013 13:52:12 +0000 (13:52 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 3 Dec 2013 13:52:12 +0000 (13:52 +0000)
Backport from mainline
2013-12-03  Marek Polacek  <polacek@redhat.com>

PR c/59351
* c-decl.c (build_compound_literal): Allow compound literals with
empty initial value.

From-SVN: r205632

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr59351.c [new file with mode: 0644]

index 3249195de5dcdac783015d2237fe0a8b1336373f..649926ba20210bda8911bf46533d2a6da4f32cf6 100644 (file)
@@ -1,3 +1,12 @@
+2013-12-03  Marek Polacek  <polacek@redhat.com>
+
+       Backport from mainline
+       2013-12-03  Marek Polacek  <polacek@redhat.com>
+
+       PR c/59351
+       * c-decl.c (build_compound_literal): Allow compound literals with
+       empty initial value.
+
 2013-12-01  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/i386/winnt.c (i386_pe_asm_named_section): Be prepared for an
index de46578e0bfbee57a38bda25d544da4481227949..2c3b8ac0ce8281d3bd45680b17910b5eb41d05bc 100644 (file)
@@ -4618,7 +4618,9 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const)
     {
       int failure = complete_array_type (&TREE_TYPE (decl),
                                         DECL_INITIAL (decl), true);
-      gcc_assert (!failure);
+      /* If complete_array_type returns 3, it means that the
+        initial value of the compound literal is empty.  Allow it.  */
+      gcc_assert (failure == 0 || failure == 3);
 
       type = TREE_TYPE (decl);
       TREE_TYPE (DECL_INITIAL (decl)) = type;
index 09ff06ffb554d37f6de8c3c40a9d249f6402a727..2b24ea544f6016b4516608855187fd91f2b3c9ae 100644 (file)
@@ -1,3 +1,11 @@
+2013-12-03  Marek Polacek  <polacek@redhat.com>
+
+       Backport from mainline
+       2013-12-03  Marek Polacek  <polacek@redhat.com>
+
+       PR c/59351
+       * gcc.dg/pr59351.c: New test.
+
 2013-11-28  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/pr59351.c b/gcc/testsuite/gcc.dg/pr59351.c
new file mode 100644 (file)
index 0000000..384058f
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -Wpedantic" } */
+
+unsigned int
+foo (void)
+{
+  return sizeof ((int[]) {}); /* { dg-warning "ISO C forbids empty initializer braces" } */
+}