Undefined Behavior in 2017
blog.regehr.org
Undefined Behavior in 2017
1–10 of 120 posts
Re: Undefined Behavior in 2017
#2Re: Undefined Behavior in 2017
#3How many of these 200+ undefined behaviours exist in more modern low-level languages, such as Rust and D?
Re: Undefined Behavior in 2017
#4How many of these 200+ undefined behaviours exist in more modern low-level languages, such as Rust and D?
Dereferencing null or dangling pointers
Reading uninitialized memory
Breaking the pointer aliasing rules
Producing invalid primitive values:
dangling/null references
a bool that isn't 0 or 1
an undefined enum discriminant
a char outside the ranges [0x0, 0xD7FF] and [0xE000, 0x10FFFF]
a non-utf8 str
Unwinding into another language
Causing a data race
Note that all of these are inside of unsafe blocks. Besides unsafe blocks, Rust has no undefined behavior, and the compiler will prevent you from doing any of these things.Re: Undefined Behavior in 2017
#5How many of these 200+ undefined behaviours exist in more modern low-level languages, such as Rust and D?
None exist in (safe) Rust.
Re: Undefined Behavior in 2017
#6Re: Undefined Behavior in 2017
#7Why don't compilers have an option to reject UB with an compiler error? Surely the compiler must know when it comes across a piece of source code whose semantic is undefined.
Re: Undefined Behavior in 2017
#8Why don't compilers have an option to reject UB with an compiler error? Surely the compiler must know when it comes across a piece of source code whose semantic is undefined.
Re: Undefined Behavior in 2017
#9Why don't compilers have an option to reject UB with an compiler error? Surely the compiler must know when it comes across a piece of source code whose semantic is undefined.
Absolutely not. Many instances of UB depend on runtime values. (E.g. overflows, out-of-bounds shifts, etc. etc.)
Re: Undefined Behavior in 2017
#10Why don't compilers have an option to reject UB with an compiler error? Surely the compiler must know when it comes across a piece of source code whose semantic is undefined.
Some undefined behaviours relate to runtime values. !iirc! signed 2+2 is safe but signed SIGNED_INT_MAX + 1 is not.