C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 23 Aug 2025 02:25:06 -0400
On Sat, Aug 23, 2025 at 2:15 AM organicoman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> The direct answer to "why is it not a reference" is the same as for why
> we have "*this" - these features were added to the language early, long
> before we even had references.
>
> C++ has a long history of not removing existing parts of the language,
> but instead add new alternatives. This is one of those cases - delete
> uses a pointer, because it always has.
>
> But if we change it from a copy to a reference, it won't break anything.
> The call sites will be the same, and the function signature is compatible. So?

It won't fix anything either. It will have the same standard-defined
behavior as before.

Making a change to the standard that doesn't actually change the way
the code behaves as far as the standard is concerned doesn't really
make sense.

The use of a pointer that was just deleted is *not* how most
use-after-free problems manifest. They usually manifest in pointers to
members or base classes from places that were unaware of the object
being freed. We can easily detect use-after-free problems of the form
your suggestion would detect, so there's nothing to be gained by this
even outside of the fact that there wouldn't be any change in standard
behavior.

If you want to fix use-after-free in a way that's meaningful to actual
C++ programmers, this just isn't it.

Received on 2025-08-23 06:25:18