diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-31 20:57:44 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-31 20:57:44 +0000 |
commit | 6a7c94af983717e2c2d6aebe42cb4737c1c7b9e6 (patch) | |
tree | 6bf91b80cdb184e81bb3b7d4c606d789529f6ab0 | |
parent | aa97b53175ef138144f69dbc7fda6870c5740226 (diff) |
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
-rw-r--r-- | lib/AST/ExprConstant.cpp | 9 | ||||
-rw-r--r-- | 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}} |