re PR c/70851 (internal compiler error: in create_tmp_var, at gimple-expr.c:473)
authorMarek Polacek <polacek@redhat.com>
Mon, 2 May 2016 11:35:59 +0000 (11:35 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 2 May 2016 11:35:59 +0000 (11:35 +0000)
PR c/70851
* c-decl.c (grokdeclarator): Diagnose when array's size has an
incomplete type.

* gcc.dg/enum-incomplete-3.c: New test.

From-SVN: r235750

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

index f02fbdb3399e60d8739e8dc0792747e8532414c4..793186bfb63b19c4be4eec1eac80350950fc3e3b 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/70851
+       * c-decl.c (grokdeclarator): Diagnose when array's size has an
+       incomplete type.
+
 2016-04-29  Cesar Philippidis  <cesar@codesourcery.com>
 
        PR middle-end/70626
index 16e4250194a8eee026e502c480ec53f2b59e65f5..7094efc5dfe2dc00e2f624b845ee7c00bd719907 100644 (file)
@@ -5799,10 +5799,21 @@ grokdeclarator (const struct c_declarator *declarator,
                  {
                    if (name)
                      error_at (loc, "size of array %qE has non-integer type",
-                               name);
+                               name);
                    else
                      error_at (loc,
-                               "size of unnamed array has non-integer type");
+                               "size of unnamed array has non-integer type");
+                   size = integer_one_node;
+                 }
+               /* This can happen with enum forward declaration.  */
+               else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
+                 {
+                   if (name)
+                     error_at (loc, "size of array %qE has incomplete type",
+                               name);
+                   else
+                     error_at (loc, "size of unnamed array has incomplete "
+                               "type");
                    size = integer_one_node;
                  }
 
index c4f45fa8b6c2028aa12c060e50936d74f5fad63b..3d6051cf8841c4f439abed1b01a9872aa974f2e1 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/70851
+       * gcc.dg/enum-incomplete-3.c: New test.
+
 2016-05-02  Marek Polacek  <polacek@redhat.com>
            Tom de Vries  <tom@codesourcery.com>
 
diff --git a/gcc/testsuite/gcc.dg/enum-incomplete-3.c b/gcc/testsuite/gcc.dg/enum-incomplete-3.c
new file mode 100644 (file)
index 0000000..db1138b
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR c/70851 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+enum E e; /* { dg-error "storage size" } */
+
+void bar (int [e]); /* { dg-error "size of unnamed array has incomplete type" } */
+void bar2 (int [][e]); /* { dg-error "size of unnamed array has incomplete type" } */
+
+void
+foo (void)
+{
+  int a1[e]; /* { dg-error "size of array .a1. has incomplete type" } */
+  int a2[e][3]; /* { dg-error "size of array .a2. has incomplete type" } */
+
+  struct S
+  {
+    int a3[e]; /* { dg-error "size of array .a3. has incomplete type" } */
+  };
+}