]> granicus.if.org Git - clang/commitdiff
Support initialization of incomplete array with zero size (as
authorDaniel Dunbar <daniel@zuster.org>
Mon, 18 Aug 2008 20:28:46 +0000 (20:28 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 18 Aug 2008 20:28:46 +0000 (20:28 +0000)
  extension).

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

lib/Sema/SemaInit.cpp
test/Sema/array-init.c

index 7c48a110b2b14d309ede6a2ba9930ec007b87401..12ca3820dd495c23c5ba94c0bbf1ffb3b2a6d425 100644 (file)
@@ -257,19 +257,18 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
   }
   if (DeclType->isIncompleteArrayType()) {
     // If this is an incomplete array type, the actual type needs to
-    // be calculated here
+    // be calculated here.
     if (numElements == 0) {
-      // Sizing an array implicitly to zero is not allowed
-      // (It could in theory be allowed, but it doesn't really matter.)
+      // Sizing an array implicitly to zero is not allowed by ISO C,
+      // but is supported by GNU.
       SemaRef->Diag(IList->getLocStart(),
-                    diag::err_at_least_one_initializer_needed_to_size_array);
-      hadError = true;
-    } else {
-      llvm::APSInt ConstVal(32);
-      ConstVal = numElements;
-      DeclType = SemaRef->Context.getConstantArrayType(elementType, ConstVal, 
-                                                       ArrayType::Normal, 0);
+                    diag::ext_typecheck_zero_array_size);
     }
+
+    llvm::APSInt ConstVal(32);
+    ConstVal = numElements;
+    DeclType = SemaRef->Context.getConstantArrayType(elementType, ConstVal, 
+                                                     ArrayType::Normal, 0);
   }
 }
 
index 7aecdda40e840a59c4e927bdac0ebf0406e0d8d1..24a0070c1fd870f1ed78bbf9839368239e7ded9f 100644 (file)
@@ -158,7 +158,7 @@ void charArrays()
   char c3[5] = { "Hello" };
   char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}}
 
-  int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}}
+  int i3[] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
 }
 
 void variableArrayInit() {