]> granicus.if.org Git - clang/commitdiff
allow cast from array to int to be considered as constant
authorNuno Lopes <nunoplopes@sapo.pt>
Mon, 2 Feb 2009 16:07:41 +0000 (16:07 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Mon, 2 Feb 2009 16:07:41 +0000 (16:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63519 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/static-init.c

index 7d7badd2cb6c6b696472b055355f8974f0d58255..fe7ab92b6a9223ff6da570d44d5c58770e51c894 100644 (file)
@@ -2075,8 +2075,7 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
     if (SubExpr->getType()->isPointerType()) {
       const Expr* Base = FindExpressionBaseAddress(SubExpr);
       // If the pointer has a null base, this is an offsetof-like construct
-      if (!Base)
-        return CheckAddressConstantExpression(SubExpr);
+      return Base ? false : CheckAddressConstantExpression(SubExpr);
     }
 
     InitializerElementNotConstant(Init);
index 2f1380062d3206782bf89ecdb124acacbc1e909a..a4035e69df466f14dbc343169aede19ae68bf93e 100644 (file)
@@ -2,6 +2,18 @@
 static int f = 10;
 static int b = f; // expected-error {{initializer element is not a compile-time constant}}
 
-float r  = (float) &r; // expected-error {{initializer element is not a compile-time constant}}
+float r  = (float) &r; // FIXME: should give an error: ptr value used where a float was expected
 long long s = (long long) &s;
 _Bool t = &t;
+
+
+union bar {
+       int i;
+};
+
+struct foo {
+       unsigned ptr;
+};
+
+union bar u[1];
+struct foo x = {(int) u}; // no-error