C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Delete...why not a parameter by reference?!

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Sat, 30 Aug 2025 08:51:43 +0200
> On Aug 27, 2025, at 9:41 PM, organicoman via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> In the example above, we have a double free bug despite the correct code.
>
It is not correct code. With or without the ‘throw’ you’ll have a double free. The destructor of A always gets called at some point. You are violating basic class invariance principles of RAII. And again: a unique_ptr would have solved this problem without any overhead.
>
> Anyway, I'm past this proposal now. If it is difficult to be understood, it will be difficult to be advocated for, thus not worth the effort.

Actually, your proposal is quite easy to understand: You want to automatically null a pointer when it gets deleted. It is just impossible to implement without breaking any (reasonable) existing C++ code (unless recompiled).

And again: A compiler flag would work just as well. And the compiler flag wouldn’t even break any code. But, compiler flags don’t belong into the standard.

Received on 2025-08-30 06:51:57