From 0d4dcf2bb3bd06f16a215a55893e34141093ffe9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 1 Oct 2019 00:41:16 +0000 Subject: [PATCH] During constant evaluation, handle CXXBindTemporaryExprs for array-of-class types, not just for class types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373279 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 13 ++++++------- test/SemaCXX/constant-expression-cxx2a.cpp | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 5659a0eced..cf28ecbe5f 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -6493,6 +6493,12 @@ public: return StmtVisitorTy::Visit(E->getSubExpr()) && Scope.destroy(); } + // Temporaries are registered when created, so we don't care about + // CXXBindTemporaryExpr. + bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) { + return StmtVisitorTy::Visit(E->getSubExpr()); + } + bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) { CCEDiag(E, diag::note_constexpr_invalid_cast) << 0; return static_cast(this)->VisitCastExpr(E); @@ -8448,13 +8454,6 @@ namespace { bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E); bool VisitCXXConstructExpr(const CXXConstructExpr *E, QualType T); bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E); - - // Temporaries are registered when created, so we don't care about - // CXXBindTemporaryExpr. - bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) { - return Visit(E->getSubExpr()); - } - bool VisitBinCmp(const BinaryOperator *E); }; } diff --git a/test/SemaCXX/constant-expression-cxx2a.cpp b/test/SemaCXX/constant-expression-cxx2a.cpp index 2f23975e2e..ef3ce5c0cc 100644 --- a/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/test/SemaCXX/constant-expression-cxx2a.cpp @@ -802,6 +802,11 @@ namespace dtor { return true; } static_assert(run_dtors_on_array_filler()); + + // Ensure that we can handle temporary cleanups for array temporaries. + struct ArrElem { constexpr ~ArrElem() {} }; + using Arr = ArrElem[3]; + static_assert((Arr{}, true)); } namespace dynamic_alloc { -- 2.40.0