[clang] [C++20] Deleting destructors can be noexcept (PR #118687)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 11:47:36 PST 2024


================
@@ -1205,11 +1205,12 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
     if (DTy.isNull() || DTy->isDependentType()) {
       CT = CT_Dependent;
     } else {
-      CT = canCalleeThrow(*this, DE, DE->getOperatorDelete());
+      const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
+      CT = canCalleeThrow(*this, DE, OperatorDelete);
       if (const RecordType *RT = DTy->getAs<RecordType>()) {
         const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
         const CXXDestructorDecl *DD = RD->getDestructor();
-        if (DD)
+        if (DD && !OperatorDelete->isDestroyingOperatorDelete())
----------------
zygoloid wrote:

Micro-optimization: looks like we could move the destroying delete check further out. There's no need to go looking for a destructor if we have a destroying delete. (`getDestructor` does a name lookup; it's not entirely trivial work.)

https://github.com/llvm/llvm-project/pull/118687


More information about the cfe-commits mailing list