diff options
-rw-r--r-- | AST/Expr.cpp | 4 | ||||
-rw-r--r-- | test/Sema/compound-literal.c | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 236c783922..726e4939cc 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -469,6 +469,10 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { return TR->isArrayType(); return false; } + case CompoundLiteralExprClass: + if (Loc) *Loc = getLocStart(); + // Allow "(int []){2,4}", since the array will be converted to a pointer. + return TR->isArrayType(); case UnaryOperatorClass: { const UnaryOperator *Exp = cast<UnaryOperator>(this); diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index f57159ac6a..2c9595c50e 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -2,9 +2,16 @@ struct foo { int a, b; }; +static struct foo t = (struct foo){0,0}; // -expected-error {{initializer element is not constant}} +static struct foo t2 = {0,0}; +static struct foo t3 = t2; // -expected-error {{initializer element is not constant}} +static int *p = (int []){2,4}; +static int x = (int){1}; // -expected-error {{initializer element is not constant}} -expected-warning{{braces around scalar initializer}} + extern void fooFunc(struct foo *pfoo); int main(int argc, char **argv) { fooFunc(&(struct foo){ 1, 2 }); } + |