C++ Logo


Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 03 Sep 2022 09:43:33 -0300
On Saturday, 3 September 2022 07:46:21 -03 blacktea hamburger via Std-
Proposals wrote:
> 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.

Correct, it does disallow.

> 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.

Why should it be legal?

Replace char there with a non-trivial type.

Also, please explain why you can't just fix the original code to have a proper
new expression.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2022-09-03 12:43:35