[cfe-commits] r54946 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/array-init.c

Daniel Dunbar daniel at zuster.org
Mon Aug 18 13:28:47 PDT 2008


Author: ddunbar
Date: Mon Aug 18 15:28:46 2008
New Revision: 54946

URL: http://llvm.org/viewvc/llvm-project?rev=54946&view=rev
Log:
Support initialization of incomplete array with zero size (as
  extension).

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/array-init.c

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=54946&r1=54945&r2=54946&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Aug 18 15:28:46 2008
@@ -257,19 +257,18 @@
   }
   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);
   }
 }
 

Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=54946&r1=54945&r2=54946&view=diff

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Mon Aug 18 15:28:46 2008
@@ -158,7 +158,7 @@
   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() {





More information about the cfe-commits mailing list