C++ Logo

std-proposals

Advanced search

Re: [std-proposals] delete p = nullptr;

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 20 Dec 2022 07:07:27 +0000
On Tue, Dec 20, 2022 at 7:00 AM connor horman via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> TBH, delete p = nullptr; reads too much like delete (p = nullptr);, even if it doesn't parse that way,
> that I wouldn't ever want to use it, or attempt reading code that uses it.


If you parse it like that, you know that it's pointless. You know that
you wouldn't bother delete'ing a nullptr.

The following two lines of code make no sense:

    p = nullptr;
    delete p;

Therefore when you see "delete p = nullptr;", irrespective of whether
you're familiar with operator
precedence, you know that it must be setting the pointer to null after
delete'ing it, because nothing
else makes sense.

Received on 2022-12-20 07:07:36