Much that is UB deserves to be defined. And some that is defined deserves to be UB. Can you make it illegal? Then do not be too eager to deal out behaviors in standardization.
I don't actually oppose, in the long run, slowly picking some behaviors and changing them to be standardized. But I do vehemently oppose many of the suggestions that are brought up. The kinds of things that should be moved out of being undefined are things like "you named your function isfoo" and not "you passed NULL to memset".
> And some that is defined deserves to be UB.
Can you provide an example of currently specified behaviour that should be UB?
To be very clear I am using specification language here. "Unspecified behaviour" is very much not "undefined behaviour".
It's an LoTR joke: "Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement"
Undefined behaviour is great. I for one will continue to vote in its favour.
C++ does not add runtime overhead to validate that programs are well-formed.
Can you provide examples of UB that could be unspecified behaviour, where UB does anything other than cause harm?
Dereferencing a pointer to memory that doesn't point to a live valid object is undefined behaviour. You couldn't possibly specify what this does without instrumenting every single access to memory, like asan or valgrind does.
As I said, behaviour that could be unspecified rather than undefined.
This is an example of something that cannot be anything other than UB.
https://www.youtube.com/watch?v=yG1OZ69H_-o is a great talk on this
Re:RFC: C++ Buffer Hardening
by staticassertion on Thursday October 06, 2022 @05:02AM
(#33106131)
> C++ does not add runtime overhead to validate that programs are well-formed.
You have succinctly described the problem.
The fact the UB is still being used as an excuse to clearly undermine reasonably expected behaviour remains a BS trope, and WG21's continued acceptance of new features and specifications that say perfectly specifiable behaviour is UB instead of unspecified is a continuing source of avoidable security bugs.
It is inexcusable for new features to be added to C++ that have UB in any case other than the undefinable (invalid memory access, etc). Removing the copious unnecessary UB from the existing specs should be a higher priority that many of the new features being proposed.