I know that I can throw meaningful exceptions and check every pointer before dereference.
What I want is to help me and others avoid mistaking one or more dereferences.
I believe that this is about safety and usability, it is easier to write:

try p1->p2->get(0);
catch (nullptr) …

than checking a line of those pointers:

if(!p1) return;
if(!p1->p2) return;
return p1->p2->get(0);

All I’m trying to get is an easier and foolproof method to not make a mistake and allow others to also avoid them.
It would be even possible to make it a some form of a compiler macro to expand it towards those ifs and some exception being thrown.

Cheers, Filip

Wiadomość napisana przez Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org> w dniu 18 lut 2025, o godz. 21:26:

On Tuesday, 18 February 2025 16:53:27 Brasilia Standard Time Jennifier Burnett
via Std-Proposals wrote:
What's actually being proposed (checking only specific annotated
dereferences) _would_ require individual checks, however. Or else the trap
handler would have to consult a table to determine if the nullptr
dereference it's just caught is one that was annotated and should throw or
is an organic nullptr dereference and should "merely" create a crash dump
and/or break into an attached debugger.

Attempting to create such a crash handler in the Standard Library or the C++
runtime will collide with all existing crash handlers in applications and
libraries.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
 Principal Engineer - Intel DCAI Platform & System Engineering



--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals