[clang] [C++20] Destroying delete and deleted destructors (PR #118800)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 11:09:02 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
----------------
zygoloid wrote:
This comment doesn't match the code, which always considers the `operator delete`.
Would it make sense to move `IsDtorCalled` onto `CXXDeleteExpr` so you can call it from here too?
https://github.com/llvm/llvm-project/pull/118800
More information about the cfe-commits
mailing list