[cfe-commits] r150870 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Fri Feb 17 20:58:19 PST 2012
Author: rsmith
Date: Fri Feb 17 22:58:18 2012
New Revision: 150870
URL: http://llvm.org/viewvc/llvm-project?rev=150870&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=150870&r1=150869&r2=150870&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Feb 17 22:58:18 2012
@@ -952,8 +952,10 @@
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 @@
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*>();
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=150870&r1=150869&r2=150870&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Fri Feb 17 22:58:18 2012
@@ -1198,3 +1198,13 @@
* 3;
}
}
+
+namespace CompoundLiteral {
+ // FIXME:
+ // We don't model the semantics of this correctly: the compound literal is
+ // represented as a prvalue in the AST, but actually behaves like an lvalue.
+ // We treat the compound literal as a temporary and refuse to produce a
+ // pointer to it. This is OK: we're not required to treat this as a constant
+ // in C++, and in C we model compound literals as lvalues.
+ constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expression}} expected-note 2{{temporary}}
+}
More information about the cfe-commits
mailing list