C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 1 Oct 2022 09:48:59 -0400
On Sat, Oct 1, 2022 at 9:41 AM blacktea hamburger via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Sun, Sep 4, 2022 at 8:58 PM Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> On Sunday, 4 September 2022 03:45:51 CDT blacktea hamburger via Std-Proposals
>> wrote:
>> > Well, it doesn't quite make sense, but it's possible. I think the standard
>> > should allow all possible and logically plausible codes.
>>
>> No, it shouldn't and doesn't. There are very good reasons to disallow certain
>> code that some people may reasonably find logical (such as signed integer
>> overload). So your argument is not going to hold water.
>>
>> If you want the standard to change, then provide a good and different argument.
>
>
> It can help with optimization, see https://www.airs.com/blog/archives/120.
>
>> > The wording of [expr.delete]/2 seems to only take into account that objects
>> > can only be created by new expressions (since IOC was added very late), and
>> > that's the issue.
>>
>> I don't see the issue. Why can;'t you new this object using the placement new?
>
>
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0593r6.html#approach:
>
> The above snippets have a common theme: they attempt to use objects that they never created. Indeed, there is a family of types for which programmers assume they do not need to explicitly create objects. We propose to identify these types, and carefully carve out rules that remove the need to explicitly create such objects, by instead creating them implicitly.

I don't understand what you're trying to say here. IOC is for cases
where you implicitly create objects, where you *don't* use object
`new`.

If you don't use object `new`, what would possess you to use object
`delete` for them? *Especially* since IOC only works on objects with
(among other things) trivial destructors. That's what confuses me
about your example; it lacks symmetry.

You use memory-allocating `new`, but then object-destroying `delete`.
It makes no sense. Your code should have symmetry; if you use
memory-allocating `new`, you should use memory-allocating `delete`.

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).

Received on 2022-10-01 13:50:13