Date: Sun, 24 Aug 2025 17:41:42 +0200
On 24/08/2025 16:41, organicoman wrote:
>
>
>> That would be nice - if it had the slightest influence on the issue,
>> which it does not.
>
>> If you use "delete p;", and then try to dereference p, then the
>> behaviour is undefined. /Anything/ can happen - including launching
>> nasal daemons, or crashing the program, or deleting your files, or
>> coincidentally doing something useful. It does not matter if "p" is
>> assigned to nullptr, left unchanged, or has a random value - the
>> behaviour is still undefined.
>
> Yes true, but atleast you can check if a delete was called on your
> pointer, then you can do this:
>
> if (m_ptr) // if false then definitely deleted.
>
Anyone who is able to check their pointers before use, is equally able
to assign 0 to deleted pointers.
A language change only helps people avoid mistakes if it does so
automatically or with significantly greater convenience than they
already have. Your suggestion only helps people who are careful in
their coding, and those people are already careful and don't make the
mistakes that your change could prevent.
If you want to help less careful programmers avoid mistakes, campaign
for std::unique_ptr and friends to have validity checking on
dereference, throwing exceptions on null pointers. (The campaign
wouldn't work because people don't want that extra overhead.)
>
>
>> That would be nice - if it had the slightest influence on the issue,
>> which it does not.
>
>> If you use "delete p;", and then try to dereference p, then the
>> behaviour is undefined. /Anything/ can happen - including launching
>> nasal daemons, or crashing the program, or deleting your files, or
>> coincidentally doing something useful. It does not matter if "p" is
>> assigned to nullptr, left unchanged, or has a random value - the
>> behaviour is still undefined.
>
> Yes true, but atleast you can check if a delete was called on your
> pointer, then you can do this:
>
> if (m_ptr) // if false then definitely deleted.
>
Anyone who is able to check their pointers before use, is equally able
to assign 0 to deleted pointers.
A language change only helps people avoid mistakes if it does so
automatically or with significantly greater convenience than they
already have. Your suggestion only helps people who are careful in
their coding, and those people are already careful and don't make the
mistakes that your change could prevent.
If you want to help less careful programmers avoid mistakes, campaign
for std::unique_ptr and friends to have validity checking on
dereference, throwing exceptions on null pointers. (The campaign
wouldn't work because people don't want that extra overhead.)
Received on 2025-08-24 15:41:47