C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 02 Oct 2022 13:11:12 -0700
On Sunday, 2 October 2022 07:32:25 PDT Jason McKesson via Std-Proposals wrote:
> > In fact, it is very simple, when the storage to be allocated is larger
> > than the object occupies. inlined_fixed_string in P0722R1 is an example,
> > It uses new (::operator new(full_size)) inlined_fixed_string(data.size(),
> > data.c_str()) to allocate and delete-expression can be used to
> > deallocate.
> That's... actually a pretty good example.

Except it isn't, in the presence of sized operators delete. I don't know why
the standard Clang didn't, but the other three compilers passed the size to
operator delete, in https://gcc.godbolt.org/z/eYWW7hafb.

So this can be done only if the type in question has its own operator new
(probably private) and delete and by controlling them, you know what they will
do or not do.

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

Received on 2022-10-02 20:11:15