[cfe-commits] r45764 - in /cfe/trunk: AST/Expr.cpp test/Sema/compound-literal.c

Steve Naroff snaroff at apple.com
Tue Jan 8 16:05:37 PST 2008


Author: snaroff
Date: Tue Jan  8 18:05:37 2008
New Revision: 45764

URL: http://llvm.org/viewvc/llvm-project?rev=45764&view=rev
Log:

Teach Expr::isConstantExpr() about CompoundLiterals.


Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/test/Sema/compound-literal.c

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45764&r1=45763&r2=45764&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Tue Jan  8 18:05:37 2008
@@ -469,6 +469,10 @@
       return TR->isArrayType();
     return false;
   }
+  case CompoundLiteralExprClass:
+    if (Loc) *Loc = getLocStart();
+    // Allow "(int []){2,4}", since the array will be converted to a pointer.
+    return TR->isArrayType();
   case UnaryOperatorClass: {
     const UnaryOperator *Exp = cast<UnaryOperator>(this);
     

Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=45764&r1=45763&r2=45764&view=diff

==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Tue Jan  8 18:05:37 2008
@@ -2,9 +2,16 @@
 
 struct foo { int a, b; };
 
+static struct foo t = (struct foo){0,0}; // -expected-error {{initializer element is not constant}}
+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}}
+
 extern void fooFunc(struct foo *pfoo);
 
 int main(int argc, char **argv) {
  fooFunc(&(struct foo){ 1, 2 });
 }
 
+





More information about the cfe-commits mailing list