From: Daniel Dunbar Date: Mon, 18 Aug 2008 20:28:46 +0000 (+0000) Subject: Support initialization of incomplete array with zero size (as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=396f0bfd4b2189452914893ce69f5fb068d0ec22;p=clang Support initialization of incomplete array with zero size (as extension). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54946 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 7c48a110b2..12ca3820dd 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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); } } diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index 7aecdda40e..24a0070c1f 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -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() {