y true.
This is not an easy feat. We owe a debt of gratitude to the folks who cumulatively put engineer-centuries into making it so. It's Thanksgiving, and I thank you!
Errata and edit history
2022-11-29: Items 13-16 corrected and updated
The original version of this post contained the following items at positions 13-16 in the list:
- But if the line with UB isn't executed, then the program will work normally as if the UB wasn't there.
- Okay, but if the line with UB is unreachable (dead) code, then it's as if the UB wasn't there. Surprising, right? It isn't obvious why code that should be perfectly safe to delete would have any effect on the behavior of the program. But it turns out that sometimes optimizations can make some dead code live again. EDIT: This was originally footnote #6 before being moved down here.
- If the line with UB is unreachable code, then the program won't crash because of the UB.
- If the line with UB is unreachable code, then the program will at least stop running somehow and at some point.
This wording was not precise enough, and as a result the claims were arguably incorrect as stated. I have updated the post near those claims to better capture the subtleties involved.
2022-11-29: Added community-contributed items
The "False expectations around UB, in general" section now contains a selection of community-suggested items. Previously it only contained a single item (the last one in the current list) at position number 41.
Thanks to arriven, Conrad Ludgate, sharnoff, Brian Graham, and a few folks who preferred to remain unnamed, for feedback on drafts of this post. Any mistakes are mine alone.