cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2889 [expr.delete] use of destroying delete requires accessible destructor #532

Open vasama opened 2 months ago

vasama commented 2 months ago

Full name of submitter: Lauri Vasama

Reference: [expr.delete]

Issue description:

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, evaluating the delete-expression invokes the destructor (if any) for the object or the elements of the array being deleted. The destructor shall be accessible from the point where the delete-expression appears.

The second sentence is not conditional on whether the selected deallocation function is a destroying operator delete, though it surely should be.

Suggested resolution:

Modify the sentence as follows:

If invoked, the destructor shall be accessible from the point where the delete-expression appears.

Related LLVM issue: https://github.com/llvm/llvm-project/issues/46818

t3nsor commented 2 months ago

If invoked, the destructor shall be accessible ...

Whether or not it's invoked depends on whether the pointer is null, which isn't known at compile time.

I think what we want to say is something like this:

If the type of the operand of the delete-expression is a pointer to a class type or (possibly multidimensional) array thereof, and the selected deallocation function (see below) is not a destroying operator delete:

  • The destructor is potentially invoked ([class.dtor]).
  • If the pointer value is not null, evaluating a single-object delete expression destroys the object pointed to by the operand, and evaluating an array delete expression destroys each element of the array pointed to by the operand in order of decreasing index.
jensmaurer commented 1 month ago

CWG2889

t3nsor commented 1 month ago

This resolution would also resolve CWG2880.

t3nsor commented 1 month ago

Wait, sorry, I take back my previous comment. But it would actually make sense to try to fold the resolution of 2880 into this one.