]> granicus.if.org Git - clang/commitdiff
Teach Expr::isConstantExpr() about CompoundLiterals.
authorSteve Naroff <snaroff@apple.com>
Wed, 9 Jan 2008 00:05:37 +0000 (00:05 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 9 Jan 2008 00:05:37 +0000 (00:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45764 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
test/Sema/compound-literal.c

index 236c7839220abae672b2c4bf1c8741970816e13f..726e4939cc7ec6779f707f591569d0001883a3e4 100644 (file)
@@ -469,6 +469,10 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
       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);
     
index f57159ac6afc7303b1a07e7a13dd984eeaadc6d6..2c9595c50e46630364d538e73d1b616f6a8ea78e 100644 (file)
@@ -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 });
 }
 
+