C++ Logo


Advanced search

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

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sun, 2 Oct 2022 20:19:48 +0800
> UB is bad when it's *inconsistent*. Making it so that your
> creation/allocation and destruction/deallocation have to match is
> consistent. Making it so that inconsistent code sometimes works
> doesn't make the language easier to learn. It just adds complexity in
> the name of... what, exactly?

> Not. It is still not recommended (but sometimes it is really needed), but
if someone really does it, it should not be UB.

Can you give a reason why such a rule ought not be followed? Show me
> actual good code that doesn't follow this rule. Not just code that
> technically works because of some statement in the bowels of the
> standard, but code that has some kind of advantage that is arguably
> more important than having a simple rule everyone understands and can
> easily follow.

In fact, it is very simple, when the storage to be allocated is larger than
the object occupies. inlined_fixed_string in P0722R1
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0722r1.html> 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.

Received on 2022-10-02 12:20:18