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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 14:46:03 PST 2024


================
@@ -3768,6 +3768,28 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
     DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName(
                                       ArrayForm ? OO_Array_Delete : OO_Delete);
 
+    // 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.
+    //
+    // This means we should not look at the destructor for a destroying
+    // delete operator, as that destructor is never called, unless the
+    // destructor is virtual (see [expr.delete]p8.1) because then the
+    // selected operator depends on the dynamic type of the pointer.
----------------
zygoloid wrote:

I think for now it'd be reasonable to say that:

- if the destructor is virtual, `noexcept` looks only at the exception specification of the destructor
- otherwise, `noexcept` looks at the selected deallocation function and, if that function is not a destroying operator delete, also the destructor

That'd match what we do in lowering. I'm not sure how that lines up with other implementations, but it seems like the most important thing is that `noexcept` is consistent with whether an exception can actually escape from the evaluation.

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


More information about the cfe-commits mailing list