diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-19 22:01:37 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-19 22:01:37 +0000 |
commit | af2c7a194592401394233b7cbcdd3cfd0a7a38dd (patch) | |
tree | ae8033d08eeb4e5cadf1123a61c71659e4533736 /lib/AST/ExprConstant.cpp | |
parent | 1f6b39515799311277b5e85cbdc67cbc90a59890 (diff) |
Improve r146813 (for PR11595) to give an appropriate diagnostic.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146915 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index ff556c3094..630136ea7f 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2059,9 +2059,7 @@ public: 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::VisitVarDecl(const Expr *E, const VarDecl *VD) { 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 @@ public: /// 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); } |