aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-02-18 04:58:18 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-02-18 04:58:18 +0000
commitb78ae9716576399145786b93f687943f8b197170 (patch)
tree31201a1830a5977ebd0cea149d8dbf441c753f4c /lib/AST/ExprConstant.cpp
parente61eb0443a77dd178934d070f458e1a08b84eb96 (diff)
Fix a problem in the GCC testsuite, exposed by r150557. Compound literals
are represented as prvalues in C++; don't be fooled into thinking they're global lvalues. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150870 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 6cbb69dae5..fcba037afc 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -952,8 +952,10 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
switch (E->getStmtClass()) {
default:
return false;
- case Expr::CompoundLiteralExprClass:
- return cast<CompoundLiteralExpr>(E)->isFileScope();
+ case Expr::CompoundLiteralExprClass: {
+ const CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E);
+ return CLE->isFileScope() && CLE->isLValue();
+ }
// A string literal has static storage duration.
case Expr::StringLiteralClass:
case Expr::PredefinedExprClass:
@@ -1002,6 +1004,9 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc,
APValue::LValueBase Base = LVal.getLValueBase();
const SubobjectDesignator &Designator = LVal.getLValueDesignator();
+ // Check that the object is a global. Note that the fake 'this' object we
+ // manufacture when checking potential constant expressions is conservatively
+ // assumed to be global here.
if (!IsGlobalLValue(Base)) {
if (Info.getLangOpts().CPlusPlus0x) {
const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>();