[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 07:19:45 PST 2024


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

Since you're going right to `RecordDecl`, could you just do:
```suggestion
        if (const CXXRecordDecl *RD = DTy->getAsCXXRecordDecl()) {
```


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


More information about the cfe-commits mailing list