2 ms·
This isn't remotely true. Unless you use the sleight of hand that is commonly used in vastly expanding the meaning of the word "valid" to mean "the compiler ca
by mpweiher 5y ago
This isn't remotely true.
Unless you use the sleight of hand that is commonly used in vastly expanding the meaning of the word "valid" to mean "the compiler can assume there is no UB".
Which, again, isn't "ignoring the situation".
- SAI_Peregrinus 5y agoI disagree that it isn't "ignoring the situation". By analogy, if you saw a purple streetlight would you keep driving, stop, turn left, turn right, or make a U turn? You have to do something! You'd probably assume it's a prank, and treat it as a green light by proceeding normally. Compiler code gen around UB is no more complex than this, though the consequences can cause complex chains of reasoning in later optimization passes.
- mpweiher 5y agoHard disagree, your analogy is (still) incorrectly equating UB with "this should never happen". That's not what UB is. UB is "the standard doesn't say anything about this particular situation, because we intentionally left the standard incomplete". It never said "UB cannot happen". But even assuming your "purple streetlight" analogy, it exactly does not cover the "complex chains of reasoning" that the compilers then do. I saw a purple streetlight, therefore I can just assume it is green. Nope. I saw a purple streetlight, therefore I can now run over pedestrians. Nope. I saw a purple streetlight, therefore this now an airport runway. Nope. The compiler-writers' justifications don't pass even the most minimal test for coherence.