]> granicus.if.org Git - clang/commitdiff
Add some more checking for compound literals.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 20 May 2008 05:22:08 +0000 (05:22 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 20 May 2008 05:22:08 +0000 (05:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51300 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/compound-literal.c

index e5ac14e092c568291ff7654aa77bfda2ea6502cb..e85ad03694aa54d55387fdd3c486668353e6d395 100644 (file)
@@ -738,7 +738,20 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
   //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression");
   Expr *literalExpr = static_cast<Expr*>(InitExpr);
 
-  // FIXME: add more semantic analysis (C99 6.5.2.5).
+  if (literalType->isArrayType()) {
+    if (literalType->getAsVariableArrayType())
+      return Diag(LParenLoc,
+                  diag::err_variable_object_no_init,
+                  SourceRange(LParenLoc,
+                              literalExpr->getSourceRange().getEnd()));
+  } else if (literalType->isIncompleteType()) {
+    return Diag(LParenLoc,
+                diag::err_typecheck_decl_incomplete_type,
+                literalType.getAsString(),
+                SourceRange(LParenLoc,
+                            literalExpr->getSourceRange().getEnd()));
+  }
+
   if (CheckInitializerTypes(literalExpr, literalType))
     return true;
 
index 83657245f501c23c0833acf78efeb82d4e41a40c..3a4192260bf44473e1a20e90c2018158c48bef6f 100644 (file)
@@ -21,4 +21,8 @@ int main(int argc, char **argv) {
  fooFunc(&(struct foo){ 1, 2 });
 }
 
-
+struct Incomplete;
+struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
+void IncompleteFunc(unsigned x) {
+  struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
+}