C++ Logo

std-proposals

Advanced search

Re: [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 21:17:32 +0800
So why is there IOC? Because it is to prevent undefined behavior from
happening (but only for trivial types).

On Sat, Sep 3, 2022 at 8:43 PM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-09-03 13:17:59