r186859 - Fixed implementation of C89 6.5.7 p3.
Enea Zaffanella
zaffanella at cs.unipr.it
Mon Jul 22 12:10:20 PDT 2013
Author: enea
Date: Mon Jul 22 14:10:20 2013
New Revision: 186859
URL: http://llvm.org/viewvc/llvm-project?rev=186859&view=rev
Log:
Fixed implementation of C89 6.5.7 p3.
Warning should be emitted only for InitListExpr nodes.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/c89.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=186859&r1=186858&r2=186859&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 22 14:10:20 2013
@@ -7785,6 +7785,7 @@ void Sema::AddInitializerToDecl(Decl *Re
// 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)
Modified: cfe/trunk/test/Sema/c89.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=186859&r1=186858&r2=186859&view=diff
==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Mon Jul 22 14:10:20 2013
@@ -116,7 +116,12 @@ long long ll1 = /* expected-warning {{'l
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 */
}
More information about the cfe-commits
mailing list