]> granicus.if.org Git - clang/commitdiff
Refactoring and test for r143360. Support for array rvalue to pointer decay is
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 31 Oct 2011 20:57:44 +0000 (20:57 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 31 Oct 2011 20:57:44 +0000 (20:57 +0000)
needed for C++11, and will follow later.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143363 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index a12beb51792a8f17f94cea7a74b2f5ae6892c4b2..b34b59d90798c578d6136e3b9a1b3e19ba5d5078 100644 (file)
@@ -1222,10 +1222,13 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
     }
   }
   case CK_ArrayToPointerDecay:
+    // FIXME: Support array-to-pointer decay on array rvalues.
+    if (!SubExpr->isGLValue())
+      return Error(E);
+    return EvaluateLValue(SubExpr, Result, Info);
+
   case CK_FunctionToPointerDecay:
-    if (SubExpr->isGLValue() || SubExpr->getType()->isFunctionType())
-      return EvaluateLValue(SubExpr, Result, Info);
-    return Error(E);
+    return EvaluateLValue(SubExpr, Result, Info);
   }
 
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
index 8cfa7ea6f87959ba1fabcccfd61609b839ba276e..df56b06e48c8185c3138b09c2eb9ad2032121dff 100644 (file)
@@ -92,3 +92,6 @@ double d2 = ++d; // expected-error {{not a compile-time constant}}
 
 int n = 2;
 int intLvalue[*(int*)((long)&n ?: 1)] = { 1, 2 }; // expected-error {{variable length array}}
+
+union u { int a; char b[4]; };
+char c = ((union u)(123456)).b[0]; // expected-error {{not a compile-time constant}}