diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 840a735e1b53129899d48f237b0c30716ce3f6d3..8b7c472333b239447cead24c5f9899a54f738d10 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7785,6 +7785,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // for an object that has aggregate or union type shall be // constant expressions. else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() && + isa<InitListExpr>(Init) && !Init->isConstantInitializer(Context, false)) Diag(Init->getExprLoc(), diag::ext_aggregate_init_not_constant) diff --git a/test/Sema/c89.c b/test/Sema/c89.c index 557acf6d62d8128a57e19565334522fa682daf20..2ab00b6ff088c79b25d3774c637afddb36cb1867 100644 --- a/test/Sema/c89.c +++ b/test/Sema/c89.c @@ -116,7 +116,12 @@ long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ 42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ +struct Test17 { int a; }; +struct Test17 test17_aux(void); + void test17(int v, int w) { int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ + struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ + struct Test17 t1 = test17_aux(); /* this is allowed */ }