From: Eli Friedman Date: Tue, 20 May 2008 05:22:08 +0000 (+0000) Subject: Add some more checking for compound literals. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6223c2237052dc99cc5263d4cf20cb0bff7650cd;p=clang Add some more checking for compound literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51300 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e5ac14e092..e85ad03694 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -738,7 +738,20 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression"); Expr *literalExpr = static_cast(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; diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 83657245f5..3a4192260b 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -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}} +}