diff options
-rw-r--r-- | Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/Sema/compound-literal.c | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 7d224c5e80..897432578b 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -664,8 +664,9 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, Expr *literalExpr = static_cast<Expr*>(InitExpr); // FIXME: add more semantic analysis (C99 6.5.2.5). - if (CheckInitializer(literalExpr, literalType, false)) - return 0; + bool requireConstantExprs = !CurFunctionDecl && !CurMethodDecl; + if (CheckInitializer(literalExpr, literalType, requireConstantExprs)) + return true; return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr); } diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 2c9595c50e..12ee9f9300 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -1,4 +1,4 @@ -// RUN: clang -fsyntax-only -verify %s +// RUN: clang -fsyntax-only -verify -pedantic %s struct foo { int a, b; }; @@ -8,9 +8,13 @@ static struct foo t3 = t2; // -expected-error {{initializer element is not const static int *p = (int []){2,4}; static int x = (int){1}; // -expected-error {{initializer element is not constant}} -expected-warning{{braces around scalar initializer}} +static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}} +static int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char *', expected 'int'}} + extern void fooFunc(struct foo *pfoo); int main(int argc, char **argv) { + int *l = (int []){x, *p, *p2}; fooFunc(&(struct foo){ 1, 2 }); } |