From c7cb48c4b96cbd0b7c9c90a5f7a02f3825487e45 Mon Sep 17 00:00:00 2001 From: Enea Zaffanella Date: Mon, 22 Jul 2013 19:10:20 +0000 Subject: [PATCH] Fixed implementation of C89 6.5.7 p3. Warning should be emitted only for InitListExpr nodes. llvm-svn: 186859 --- clang/lib/Sema/SemaDecl.cpp | 1 + clang/test/Sema/c89.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 840a735..8b7c472 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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(Init) && !Init->isConstantInitializer(Context, false)) Diag(Init->getExprLoc(), diag::ext_aggregate_init_not_constant) diff --git a/clang/test/Sema/c89.c b/clang/test/Sema/c89.c index 557acf6..2ab00b6 100644 --- a/clang/test/Sema/c89.c +++ b/clang/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 */ } -- 2.7.4