Comment by SAI_Peregrinus

5 months ago

It's indistinguishable from unspecified behavior, not from undefined behavior. Unspecified behavior has to pick from a finite list of allowed behaviors. Undefined behavior can do anything.

A program with corrupted state can essentially do anything. Yes it's still a question of run-time checks the runtime has to protect against it. But the compiler is probably deriving a lot of assumptions from the assumption that there wasn't overflow.

  • “Undefined behavior” is a term of art in programming languages that means something more specific than “the program may do something odd.”

    The compiler is not allowed to derive any assumptions from it. It only could if it were UB.

    • But did the rust compiler assume that the integer would not overflow? It did so in Debug mode where runtime checks were added. If it's not the case in Release mode, does that mean semantics are different between Debug and Release?

      12 replies →