Undefined Behavior in C++: What Every Programmer Should Know and Fear
Talkat CppCon 2023 · on Thursday, 2023-10-05· at 09:00· Adams, 6700 North Gaylord Rockies Boulevard·
summary
Concrete claims and reproducible demos: compilers optimize away checks because they assume no UB, so signed integer overflow turns into constant true and loop-merging depends on undefined termination, causing behavior changes across versions (GCC 9 → 10). Live examples show null-dereference checks removed and crashes appearing far from the offending line. Detection uses runtime sanitizer UBSan, which only reports exercised UB. Advice centers on defining valid input domains, adding optional validators, or isolating critical code (even in assembly) when relying on specific semantics.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 0:26What undefined behavior is
- 3:17Undefined behavior taints program
- 9:00Compiler optimizations and UB
- 13:23Why UB persists in C++
- 16:54How compilers exploit UB
- 21:10Undefined behavior travels back
- 24:28Valid inputs to avoid UB
- 27:00Undefined behavior sanitizers
- 28:49Practical consequences of UB
- 30:42Q&A
related talks
01h 02mBack To Basics: Undefined Behavior
01h 04mRemoving Needless Undefined Behavior for a Safer C++
01h 30mDangerous Optimizations in C and C++ Programming Languages
01h 02mPractical Tips for Safer C++
01h 04mUndefined Behavior in the STL
03mUndefined Behavior - Not what you expected
07mLightning Talk: The UB Detector: constexpr
01h 13mPractical Tips for Safer C++
