]> granicus.if.org Git - clang/commitdiff
Reject 'int a[1][];' in Sema rather than crashing in IR generation. Found by a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 7 Jul 2012 23:00:31 +0000 (23:00 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 7 Jul 2012 23:00:31 +0000 (23:00 +0000)
misreduction of PR13290.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159905 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/SemaCXX/array-bound-merge.cpp

index 694a94d5566b164c0c24a59fe4c91fe7bad414da..84e8a7944d97d19361cf3fb304de2e19d655d529 100644 (file)
@@ -1249,6 +1249,11 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
     //   type, the (possibly cv-qualified) type void, a function type or an
     //   abstract class type.
     //
+    // C++ [dcl.array]p3:
+    //   When several "array of" specifications are adjacent, [...] only the
+    //   first of the constant expressions that specify the bounds of the arrays
+    //   may be omitted.
+    //
     // Note: function types are handled in the common path with C.
     if (T->isReferenceType()) {
       Diag(Loc, diag::err_illegal_decl_array_of_references)
@@ -1256,7 +1261,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
       return QualType();
     }
 
-    if (T->isVoidType()) {
+    if (T->isVoidType() || T->isIncompleteArrayType()) {
       Diag(Loc, diag::err_illegal_decl_array_incomplete_type) << T;
       return QualType();
     }
index 74f58fa1236014db3d60f2a113a7a2e4933a0842..8fb2ec52a9eefe56827fe530e5c56e2665b47207 100644 (file)
@@ -7,3 +7,5 @@ extern int b[10];
 int b[];
 extern int c[1];
 int c[] = {1,2}; // expected-error {{excess elements in array initializer}}
+
+int d[1][]; // expected-error {{array has incomplete element type 'int []'}}