Date: Sat, 01 Oct 2022 08:45:01 -0700
On Saturday, 1 October 2022 07:09:47 PDT blacktea hamburger via Std-Proposals
wrote:
> > 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.
I agree it's valid, so long as the type we are talking about is really char
here. It's only correct so long as the type in question doesn't have an
overridden operator new / delete, and primitives can't have them overridden.
wrote:
> > 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.
I agree it's valid, so long as the type we are talking about is really char
here. It's only correct so long as the type in question doesn't have an
overridden operator new / delete, and primitives can't have them overridden.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Software Architect - Intel DCAI Cloud Engineering
Received on 2022-10-01 15:45:03