]> granicus.if.org Git - clang/commitdiff
Diagnose implicit init list for empty aggregate, like struct {}. Fixes
authorEli Friedman <eli.friedman@gmail.com>
Sun, 25 May 2008 13:49:22 +0000 (13:49 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 25 May 2008 13:49:22 +0000 (13:49 +0000)
PR2151 (by not creating the empty implicit init list).

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

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaInit.cpp
test/Sema/array-init.c

index beea258482b6e1ee58825f8d6a11f024fbf67d3c..ce41cfdcf6d60fcf2a8582f769cc881f4f31e8f0 100644 (file)
@@ -751,6 +751,8 @@ DIAG(err_empty_scalar_initializer, ERROR,
      "scalar initializer cannot be empty")
 DIAG(err_illegal_initializer, ERROR,
      "illegal initializer (only variables can be initialized)")
+DIAG(err_implicit_empty_initializer, ERROR,
+     "initializer for aggregate with no elements requires explicit braces")
 
 DIAG(err_redefinition_of_label, ERROR,
      "redefinition of label '%0'")
index 35dda28d4adfd55bd2befa7e107610149ae42ebe..6eb072eebafaefb381bb125d8f856f44bd41debf 100644 (file)
@@ -57,6 +57,13 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
   else
     assert(0 && "CheckImplicitInitList(): Illegal type");
 
+  if (maxElements == 0) {
+    SemaRef->Diag(ParentIList->getInit(Index)->getLocStart(),
+                  diag::err_implicit_empty_initializer);
+    hadError = true;
+    return;
+  }
+
   // Check the element types *before* we create the implicit init list;
   // otherwise, we might end up taking the wrong number of elements
   unsigned NewIndex = Index;
index a7f27b68f86b0ea239ffc19a7f0dd800f43d2aeb..69255569ddc75eeea657224c1d36fddfe9e4432e 100644 (file)
@@ -212,3 +212,7 @@ int u2 = {{3}}; //expected-error{{too many braces around scalar initializer}}
 void varArray() {
   int c[][x] = { 0 }; //expected-error{{variable-sized object may not be initialized}}
 }
+
+// PR2151
+int emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct extension}} expected-error{{initializer for aggregate with no elements}}
+