summaryrefslogtreecommitdiffstats
path: root/clang/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
commit02ab9c29403899848125dd08cc3ff7b9a5d0be8c (patch)
treee30c93add926e02086ed4994860a660d37f7cbd3 /clang/lib/AST/ExprConstant.cpp
parent4d4c988c6a60736d93b7fa0e15e33d7b1fb2492c (diff)
downloadbcm5719-llvm-02ab9c29403899848125dd08cc3ff7b9a5d0be8c.tar.gz
bcm5719-llvm-02ab9c29403899848125dd08cc3ff7b9a5d0be8c.zip
Allow constant-folding of references which were formed in a manner not permitted
in a constant expression, for compatibility with g++. llvm-svn: 148020
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 36addddcc5c..9df53cd5bf0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/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;
OpenPOWER on IntegriCloud