[cfe-commits] r53174 - in /cfe/trunk: lib/AST/Expr.cpp lib/Sema/SemaDecl.cpp test/Sema/compound-literal.c
Nuno Lopes
nunoplopes at sapo.pt
Mon Jul 7 09:46:51 PDT 2008
Author: nlopes
Date: Mon Jul 7 11:46:50 2008
New Revision: 53174
URL: http://llvm.org/viewvc/llvm-project?rev=53174&view=rev
Log:
fix CheckForConstantInitializer() for Compound Literals
also fix the correspondent test (it was expecting more errors than it should. please confirm my fix is correct (at least gcc agrees with me)
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/compound-literal.c
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=53174&r1=53173&r2=53174&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Jul 7 11:46:50 2008
@@ -670,7 +670,7 @@
/// expression. The generalization of the wording to include any subexpression
/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
-/// "0 || f()" can be treated as a constant expression. In C90 this expression,
+/// "1 || f()" can be treated as a constant expression. In C90 this expression,
/// occurring in a context requiring a constant, would have been a constraint
/// violation. FIXME: This routine currently implements C90 semantics.
/// To properly implement C99 semantics this routine will need to evaluate
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=53174&r1=53173&r2=53174&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 7 11:46:50 2008
@@ -1197,10 +1197,15 @@
}
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
+ Init = Init->IgnoreParens();
+
// Look through CXXDefaultArgExprs; they have no meaning in this context.
if (CXXDefaultArgExpr* DAE = dyn_cast<CXXDefaultArgExpr>(Init))
return CheckForConstantInitializer(DAE->getExpr(), DclT);
+ if (CompoundLiteralExpr *e = dyn_cast<CompoundLiteralExpr>(Init))
+ return CheckForConstantInitializer(e->getInitializer(), DclT);
+
if (Init->getType()->isReferenceType()) {
// FIXME: Work out how the heck reference types work
return false;
Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=53174&r1=53173&r2=53174&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Mon Jul 7 11:46:50 2008
@@ -2,15 +2,18 @@
struct foo { int a, b; };
-static struct foo t = (struct foo){0,0}; // -expected-error {{initializer element is not constant}}
+static struct foo t = (struct foo){0,0};
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}}
+static int x = (int){1}; // -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 [2]', expected 'int'}}
+typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}}
+static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
+
typedef struct Test {int a;int b;} Test;
static Test* ll = &(Test) {0,0};
More information about the cfe-commits
mailing list