c++: destroying delete, throw in new-expr [PR100588]
authorJason Merrill <jason@redhat.com>
Thu, 6 Jan 2022 18:26:21 +0000 (13:26 -0500)
committerJason Merrill <jason@redhat.com>
Sat, 8 Jan 2022 02:03:28 +0000 (21:03 -0500)
commit75047f795111150fd10a8f86f5c72deab10cde77
treea63f180ae340a0fd0282cc00b59d451118b239d3
parent55e96bf91237bc0b42fe0079006507d42c155e69
c++: destroying delete, throw in new-expr [PR100588]

The standard says that a destroying operator delete is preferred, but that
only applies to the delete-expression, not the cleanup if a new-expression
initialization throws.  As a result of this patch, several of the destroying
delete tests don't get EH cleanups, but I'm turning off the warning in cases
where the initialization can't throw anyway.

It's unclear what should happen if the class does not declare a non-deleting
operator delete; a proposal in CWG was to call the global delete, which
makes sense to me if the class doesn't declare its own operator new.  If it
does, we warn and don't call any deallocation function if initialization
throws.

PR c++/100588

gcc/cp/ChangeLog:

* call.c (build_op_delete_call): Ignore destroying delete
if alloc_fn.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/destroying-delete5.C: Expect warning.
* g++.dg/cpp2a/destroying-delete6.C: New test.
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp2a/destroying-delete5.C
gcc/testsuite/g++.dg/cpp2a/destroying-delete6.C [new file with mode: 0644]