[cfe-commits] r143905 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Sun Nov 6 19:22:51 PST 2011
Author: rsmith
Date: Sun Nov 6 21:22:51 2011
New Revision: 143905
URL: http://llvm.org/viewvc/llvm-project?rev=143905&view=rev
Log:
Allow constexpr variables' initializers to be folded in C++11 mode. This
partially undoes the revert in r143491, but does not introduce any new instances
of the underlying issue (which is not yet fixed) in code which does not use
the 'constexpr' keyword.
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=143905&r1=143904&r2=143905&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 6 21:22:51 2011
@@ -558,12 +558,14 @@
// them are not permitted.
const VarDecl *VD = dyn_cast<VarDecl>(D);
QualType VT = VD->getType();
- if (!VD)
+ if (!VD || VD->isInvalidDecl())
return false;
if (!isa<ParmVarDecl>(VD)) {
if (!IsConstNonVolatile(VT))
return false;
- if (!VT->isIntegralOrEnumerationType() && !VT->isRealFloatingType())
+ // FIXME: Allow folding of values of any literal type in all languages.
+ if (!VT->isIntegralOrEnumerationType() && !VT->isRealFloatingType() &&
+ !VD->isConstexpr())
return false;
}
if (!EvaluateVarDeclInit(Info, VD, Frame, RVal))
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=143905&r1=143904&r2=143905&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Nov 6 21:22:51 2011
@@ -135,7 +135,6 @@
}
-#if 0
namespace Pointers {
constexpr int f(int n, const int *a, const int *b, const int *c) {
@@ -165,10 +164,9 @@
static_assert_fold(1 + Apply(Select(4), 5) + Apply(Select(3), 7) == 42, "");
- constexpr int Invalid = Apply(Select(0), 0); // xpected-error {{must be initialized by a constant expression}}
+ constexpr int Invalid = Apply(Select(0), 0); // expected-error {{must be initialized by a constant expression}}
}
-#endif
namespace PointerComparison {
@@ -211,12 +209,10 @@
static_assert_fold(&x < &x, "false"); // expected-error {{false}}
static_assert_fold(&x > &x, "false"); // expected-error {{false}}
-#if 0
constexpr S* sptr = &s;
// FIXME: This is not a constant expression; check we reject this and move this
// test elsewhere.
constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr);
-#endif
extern char externalvar[];
// FIXME: This is not a constant expression; check we reject this and move this
More information about the cfe-commits
mailing list