[cfe-commits] r45782 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/compound-literal.c
Steve Naroff
snaroff at apple.com
Wed Jan 9 12:58:07 PST 2008
Author: snaroff
Date: Wed Jan 9 14:58:06 2008
New Revision: 45782
URL: http://llvm.org/viewvc/llvm-project?rev=45782&view=rev
Log:
Teach Sema::ActOnCompoundLiteral about constraint C99 6.5.2.5p3.
Modified:
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/compound-literal.c
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45782&r1=45781&r2=45782&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Jan 9 14:58:06 2008
@@ -664,8 +664,9 @@
Expr *literalExpr = static_cast<Expr*>(InitExpr);
// FIXME: add more semantic analysis (C99 6.5.2.5).
- if (CheckInitializer(literalExpr, literalType, false))
- return 0;
+ bool requireConstantExprs = !CurFunctionDecl && !CurMethodDecl;
+ if (CheckInitializer(literalExpr, literalType, requireConstantExprs))
+ return true;
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr);
}
Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=45782&r1=45781&r2=45782&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Wed Jan 9 14:58:06 2008
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify -pedantic %s
struct foo { int a, b; };
@@ -8,9 +8,13 @@
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 *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 *', expected 'int'}}
+
extern void fooFunc(struct foo *pfoo);
int main(int argc, char **argv) {
+ int *l = (int []){x, *p, *p2};
fooFunc(&(struct foo){ 1, 2 });
}
More information about the cfe-commits
mailing list