[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 10:15:58 PST 2025


================
@@ -1200,21 +1200,35 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
 
   case Expr::CXXDeleteExprClass: {
     auto *DE = cast<CXXDeleteExpr>(S);
-    CanThrowResult CT;
+    CanThrowResult CT = CT_Cannot;
     QualType DTy = DE->getDestroyedType();
     if (DTy.isNull() || DTy->isDependentType()) {
       CT = CT_Dependent;
     } else {
+      // C++20 [expr.delete]p6: If the value of the operand of the delete-
+      // expression is not a null pointer value and the selected deallocation
+      // function (see below) is not a destroying operator delete, the delete-
+      // expression will invoke the destructor (if any) for the object or the
+      // elements of the array being deleted.
+      //
+      // So if the destructor is virtual, we only look at the exception
+      // specification of the destructor regardless of what operator delete is
+      // selected. Otherwise, we look at the selected operator delete, and if
----------------
AaronBallman wrote:

Good catch on the comment!

It'd be awkward on `CXXDeleteExpr` but it does make sense on `CXXDestructorDecl`. Good call!

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


More information about the cfe-commits mailing list