From bc6abe93a5d6b1305411f8b6f54c2caa686ddc69 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 19 Dec 2011 22:12:41 +0000 Subject: [PATCH] Evaluation support for ExprWithCleanups. We won't evaluate any expression which actually requires non-trivial cleanups, so no cleanups need to be performed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146916 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 4 ++++ test/SemaCXX/constant-expression-cxx11.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 630136ea7f..3c2ffbd0f7 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1799,6 +1799,10 @@ public: { return StmtVisitorTy::Visit(E->getReplacement()); } RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { return StmtVisitorTy::Visit(E->getExpr()); } + // We cannot create any objects for which cleanups are required, so there is + // nothing to do here; all cleanups must come from unevaluated subexpressions. + RetTy VisitExprWithCleanups(const ExprWithCleanups *E) + { return StmtVisitorTy::Visit(E->getSubExpr()); } RetTy VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) { CCEDiag(E, diag::note_constexpr_invalid_cast) << 0; diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index e4ada1ed83..5798eb5948 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -923,3 +923,9 @@ namespace PR11595 { } constexpr int n = f(1); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'f(1)'}} } + +namespace ExprWithCleanups { + struct A { A(); ~A(); int get(); }; + constexpr int get(bool FromA) { return FromA ? A().get() : 1; } + constexpr int n = get(false); +} -- 2.40.0