]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/69262
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2016 17:46:25 +0000 (17:46 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2016 17:46:25 +0000 (17:46 +0000)
* c-decl.c (grokdeclarator): Provide more information for invalid
array declarations.

* gcc.dg/array-15.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232376 138bc75d-0d04-0410-961f-82ee72b054a4

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

index f8bac2d4e4b1b5b7ba1e99f51bfc846e0f7a91ea..3f40b03bc2f71cbb32f1dca7a85cd351f122a8d6 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-14  Marek Polacek  <polacek@redhat.com>
+
+       PR c/69262
+       * c-decl.c (grokdeclarator): Provide more information for invalid
+       array declarations.
+
 2016-01-06  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c (c_parser_unary_expression): For dereferences, build
index 915376d101f7d90c5f1ebf88e7f0a1be1e2c45b9..5830e22a7fc525fd8372c2d465f886799b7204ca 100644 (file)
@@ -5951,6 +5951,18 @@ grokdeclarator (const struct c_declarator *declarator,
              {
                error_at (loc, "array type has incomplete element type %qT",
                          type);
+               /* See if we can be more helpful.  */
+               if (TREE_CODE (type) == ARRAY_TYPE)
+                 {
+                   if (name)
+                     inform (loc, "declaration of %qE as multidimensional "
+                             "array must have bounds for all dimensions "
+                             "except the first", name);
+                   else
+                     inform (loc, "declaration of multidimensional array "
+                             "must have bounds for all dimensions except "
+                             "the first");
+                 }
                type = error_mark_node;
              }
            else
index 4b5e9e254d3d2dbcd09af878fdac421123651ea5..3d67923f91c700526eb4e18da9649a5167fa1b21 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-14  Marek Polacek  <polacek@redhat.com>
+
+       PR c/69262
+       * gcc.dg/array-15.c: New test.
+
 2016-01-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/68146
diff --git a/gcc/testsuite/gcc.dg/array-15.c b/gcc/testsuite/gcc.dg/array-15.c
new file mode 100644 (file)
index 0000000..a002f68
--- /dev/null
@@ -0,0 +1,52 @@
+/* PR c/69262 */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+struct S
+{
+  int a[1][][2]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .a. as multidimensional array must have bounds" "" { target *-*-* } 7 } */
+};
+
+struct R
+{
+  int i;
+  int a[][]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .a. as multidimensional array must have bounds" "" { target *-*-* } 14 } */
+};
+
+typedef int T[];
+typedef int U[][]; /* { dg-error "array type has incomplete element type" } */
+/* { dg-message "declaration of .U. as multidimensional array must have bounds" "" { target *-*-* } 19 } */
+
+int x[][]; /* { dg-error "array type has incomplete element type" } */
+/* { dg-message "declaration of .x. as multidimensional array must have bounds" "" { target *-*-* } 22 } */
+
+struct N;
+
+void
+fn1 (int z[][]) /* { dg-error "array type has incomplete element type" } */
+/* { dg-message "declaration of .z. as multidimensional array must have bounds" "" { target *-*-* } 28 } */
+{
+  int a[1][][2]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .a. as multidimensional array must have bounds" "" { target *-*-* } 31 } */
+  /* OK */
+  int b[3][2][1];
+  int c[1][2][3][]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .c. as multidimensional array must have bounds" "" { target *-*-* } 35 } */
+  T d[1]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .d. as multidimensional array must have bounds" "" { target *-*-* } 37 } */
+  T e[]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-message "declaration of .e. as multidimensional array must have bounds" "" { target *-*-* } 39 } */
+
+  /* This array has incomplete element type, but is not multidimensional.  */
+  struct N f[1]; /* { dg-error "array type has incomplete element type" } */
+  /* { dg-bogus "declaration of .f. as multidimensional array must have bounds" "" { target *-*-* } 43 } */
+}
+
+void fn2 (int [][]); /* { dg-error "array type has incomplete element type" } */
+/* { dg-message "declaration of multidimensional array must have bounds" "" { target *-*-* } 47 } */
+/* OK */
+void fn3 (int [][*]);
+void fn4 (T []); /* { dg-error "array type has incomplete element type" } */
+/* { dg-message "declaration of multidimensional array must have bounds" "" { target *-*-* } 51 } */