C++ Logo

std-proposals

Advanced search

Re: [std-proposals] try else syntax for validity check

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 18 Feb 2025 22:13:19 +0100
If that would be a language feature, some more cases, which are just UB now, would have to be checked:   Calling a static member function on a nullptr? Or accessing nullptr[index]? Or initiazing a reference variable or reference parameter with a dereferenced nullptr?   Those cases are with a typical translation not automatically detected in hardware (e.g. MMU with invalid page at address 0).   -----Ursprüngliche Nachricht----- Von:Jennifier Burnett via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 18.02.2025 20:53 Betreff:Re: [std-proposals] try else syntax for validity check An:std-proposals_at_[hidden]; CC:Jennifier Burnett <jenni_at_[hidden]>; Actually the capability of detecting nullptr dereferences (or any invalid memory access in general) is built into pretty much all hardware nowadays. Detecting ALL nullptr references and throwing an exception would be entirely free on most machines (and in fact this is what the android java runtime does, unless they've changed it). 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. On 18 February 2025 16:05:42 GMT, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote: >On Tue, Feb 18, 2025 at 10:46 AM Filip via Std-Proposals ><std-proposals_at_[hidden]> wrote: >> >> What if dereferencing nullptr would not be an undefined behavior? > >"What if we made every program significantly slower by requiring the >compiler to insert testing into every pointer dereference as well as >exception logic?" > >No, thank you. >-- >Std-Proposals mailing list >Std-Proposals_at_[hidden] >https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-02-18 21:17:38