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, 1 Oct 2022 22:09:47 +0800
>
> For example:
>
> ```
> auto *p = operator new(1);
> auto *pc = new(p) char;
> delete pc;
> ```
>
> That delete is invalid, and it *should be*. If you use two-step object
> creation (allocate memory, then put an object into it), you should use
> two-step object destruction (destroy the object, then deallocate the
> memory).
>

In fact, it is legal. The standard does not specify that a new-expression
cannot be a placement-new.

The standard should not forbid some code that is not very good, but correct.

Received on 2022-10-01 14:10:16