OOCP = Out Of Context Problem, aka Undefined Behavior.
May or may not be possible, but worth thinking about. Zig's issue on the matter is here: https://github.com/ziglang/zig/issues/2301
The way I think about it there's
twothree types of UB:There's the shit that breaks the assumptions that the compiler makes about the universe, like a wild pointer overwriting random parts of the stack. The compiler assumes that Just Doesn't Happen, checking for it at runtime would be hard and designing your language so it's impossible means taking out features that are useful.
Then in C/C++ there's the shit that the language committee can't agree on and so just calls it UB so implementations can do whatever they feel like. Like bit shifting negative numbers or calling
realloc(NULL, 0)
.I guess then there's the stuff actually there for optimization, like not defining what happens on integer overflow or infinite loop, which imo is probably never worth it.
The goal is to have none of the second and third type of UB, and minimize the first.
Types And Programming Languages (Pierce, 2003)
...a safe language is one that protects its own abstractions.
Very simple but very important distinction, thanks rpjohnst: "rust considers it a bug when safe code can have ub"