[cfe-commits] r146915 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Mon Dec 19 14:01:37 PST 2011
Author: rsmith
Date: Mon Dec 19 16:01:37 2011
New Revision: 146915
URL: http://llvm.org/viewvc/llvm-project?rev=146915&view=rev
Log:
Improve r146813 (for PR11595) to give an appropriate diagnostic.
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=146915&r1=146914&r2=146915&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Dec 19 16:01:37 2011
@@ -2059,9 +2059,7 @@
return false;
BaseTy = E->getBase()->getType()->getAs<PointerType>()->getPointeeType();
} else if (E->getBase()->isRValue()) {
- if (!E->getBase()->getType()->isRecordType() ||
- !E->getBase()->getType()->isLiteralType())
- return false;
+ assert(E->getBase()->getType()->isRecordType());
if (!EvaluateTemporary(E->getBase(), Result, this->Info))
return false;
BaseTy = E->getBase()->getType();
@@ -2242,7 +2240,7 @@
bool LValueExprEvaluator::VisitMaterializeTemporaryExpr(
const MaterializeTemporaryExpr *E) {
if (E->GetTemporaryExpr()->isRValue()) {
- if (E->getType()->isRecordType() && E->getType()->isLiteralType())
+ if (E->getType()->isRecordType())
return EvaluateTemporary(E->GetTemporaryExpr(), Result, Info);
Result.set(E, Info.CurrentCall);
@@ -2770,8 +2768,15 @@
/// Evaluate an expression of record type as a temporary.
static bool EvaluateTemporary(const Expr *E, LValue &Result, EvalInfo &Info) {
- assert(E->isRValue() && E->getType()->isRecordType() &&
- E->getType()->isLiteralType());
+ assert(E->isRValue() && E->getType()->isRecordType());
+ if (!E->getType()->isLiteralType()) {
+ if (Info.getLangOpts().CPlusPlus0x)
+ Info.Diag(E->getExprLoc(), diag::note_constexpr_nonliteral)
+ << E->getType();
+ else
+ Info.Diag(E->getExprLoc(), diag::note_invalid_subexpr_in_const_expr);
+ return false;
+ }
return TemporaryExprEvaluator(Info, Result).Visit(E);
}
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=146915&r1=146914&r2=146915&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Dec 19 16:01:37 2011
@@ -915,6 +915,11 @@
namespace PR11595 {
struct A { constexpr bool operator==(int x) { return true; } };
- struct B { B(); ~B(); A& x; };
- static_assert(B().x == 3, ""); // expected-error {{constant expression}}
+ struct B { B(); A& x; };
+ static_assert(B().x == 3, ""); // expected-error {{constant expression}} expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
+
+ constexpr bool f(int k) {
+ return B().x == k; // expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
+ }
+ constexpr int n = f(1); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'f(1)'}}
}
More information about the cfe-commits
mailing list