C++ Logo

std-proposals

Advanced search

[std-proposals] Relax the restriction on the operand of a single-object delete-expression

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sat, 3 Sep 2022 18:46:21 +0800
The description of [expr.delete] paragraph 2:

If the operand has a class type, the operand is converted to a pointer type
by calling the above-mentioned conversion function, and the converted
operand is used in place of the original operand for the remainder of this
subclause. In a single-object delete expression, the value of the operand
of delete may be a null pointer value, a pointer value that resulted from a
previous non-array new-expression, or a pointer to a base class subobject
of an object created by such a new-expression. If not, the behavior is
undefined. In an array delete expression, the value of the operand of
delete may be a null pointer value or a pointer value that resulted from a
previous array new-expression.68 If not, the behavior is undefined.


It disallows use like:

delete static_cast<char*>(operator new(1));

It destroys the implicitly created char object ([intro.object]
paragraph 13) and deallocates the memory, but the behavior is
undefined because the operand is not resulted from a previous
non-array new-expression.

But the operand of a single-object delete-expression should be legal
as long as it's a null pointer, it's resulted from operator new and
points to an object created on it, or it points to the object's base
class subobject.

I tried submitting it as a core language issue, but a proposal is
needed. Can someone help?

I'd like someone to help me write a proposal because I'm not very good
at writing these kinds of standard documents and my English is not
very good. I will be very grateful.

Received on 2022-09-03 10:46:49