aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-01-12 06:08:57 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-01-12 06:08:57 +0000
commit61e616206413d1779c7545c7a8ad1ce1129ad9c1 (patch)
tree864235e3a0798289f3c267470fde05b3c0f171a0 /lib/AST/ExprConstant.cpp
parent746f5bcbfde5b25269169c63c66492311673b67d (diff)
Allow constant-folding of references which were formed in a manner not permitted
in a constant expression, for compatibility with g++. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 36addddcc5..9df53cd5bf 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -832,7 +832,8 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
/// Check that this reference or pointer core constant expression is a valid
/// value for an address or reference constant expression. Type T should be
-/// either LValue or CCValue.
+/// either LValue or CCValue. Return true if we can fold this expression,
+/// whether or not it's a constant expression.
template<typename T>
static bool CheckLValueConstantExpression(EvalInfo &Info, const Expr *E,
const T &LVal, APValue &Value,
@@ -854,19 +855,15 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, const Expr *E,
} else {
Info.Diag(E->getExprLoc());
}
+ // Don't allow references to temporaries to escape.
return false;
}
bool IsReferenceType = E->isGLValue();
if (Designator.Invalid) {
- // This is not a core constant expression. A diagnostic will have already
- // been produced.
- if (IsReferenceType)
- return false;
-
- // Allow this for pointers, so we can fold things like integers cast to
- // pointers.
+ // This is not a core constant expression. An appropriate diagnostic will
+ // have already been produced.
Value = APValue(LVal.getLValueBase(), LVal.getLValueOffset(),
APValue::NoLValuePath());
return true;
@@ -884,7 +881,7 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, const Expr *E,
if (!Base) {
// FIXME: diagnostic
Info.CCEDiag(E->getExprLoc());
- return false;
+ return true;
}
// Does this refer one past the end of some object?
@@ -897,7 +894,6 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, const Expr *E,
else
Info.Note(Base.dyn_cast<const Expr*>()->getExprLoc(),
diag::note_constexpr_temporary_here);
- return false;
}
return true;