6 ms·
Everyone's getting confused about the word "reach". If the execution of a program triggers UB at any point then its behavior is undefined at all points, even be
by oconnor663 4y ago
Everyone's getting confused about the word "reach". If the execution of a program triggers UB at any point then its behavior is undefined at all points, even before the UB was triggered. But the compiler does have to respect and preserve the behavior of any completely UB-free execution of your program, even if other executions (say with different input) could trigger UB.
So we could say, unreachable UB is fine, but if you do reach it, then it doesn't matter when you reached it.
- leni536 4y agoPoint 14 explicitly says UB in dead code. The implicit assumption is no UB in live code, otherwise the UB in dead code is a red herring. So the UB is never reached, by the definition of dead code. Unreachable UB is fine. If this wasn't the intended message of point 14, then it's phrased wrong.
- oconnor663 4y agoYeah the format of the article makes this mistake extra confusing. The statement in point 14 is in fact true, but the whole premise is that all these statements are supposed to be false.