From 6a7c94af983717e2c2d6aebe42cb4737c1c7b9e6 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 31 Oct 2011 20:57:44 +0000 Subject: [PATCH] Refactoring and test for r143360. Support for array rvalue to pointer decay is 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 | 9 ++++++--- test/Sema/const-eval.c | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index a12beb5179..b34b59d907 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -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); diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 8cfa7ea6f8..df56b06e48 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -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}} -- 2.40.0