Back To Basics: Undefined Behavior
summary
Builds a precise definition of undefined behavior, then shows concrete, surprising instances: an infinite loop with no side effects that is UB, signed integer overflow in a cube function, UB that collapses a for loop by indexing past the end, and UB that happens at compile time by specializing a std trait. Recommends tools and fixes: sanitizers including undefined behavior sanitizer, different compilers, std::bit_cast/memcpy for type punning, and treats UB as a critical, non-recoverable bug.
AI-written summary · about
chapters (16)
- 0:00Start
- 0:56Definitions
- 1:54Introduction
- 5:30Correct Program Must Be Free of Undefined Behavior
- 10:21Undefined Behavior
- 14:23Defined Behavior
- 15:12Implementation Defined Behavior
- 15:44Unspecified Behavior
- 26:54How Is Undefined Behavior Defined
- 28:28More Common Undefined Behaviors
- 31:10Infinite Loop without Side Effects
- 32:42Signed Integer Overflow
- 35:56Is Undefined Behavior Acceptable
- 40:29Testing for Undefined Behavior
- 45:18Example with no Return Statement
- 58:56Treat Undefined Behavior as a Critical Bug
related talks
33mUndefined Behavior in C++: What Every Programmer Should Know and Fear
01h 04mUndefined Behavior in the STL
01h 04mRemoving Needless Undefined Behavior for a Safer C++
03mUndefined Behavior - Not what you expected
01h 30mDangerous Optimizations in C and C++ Programming Languages
07mLightning Talk: The UB Detector: constexpr
01h 02mPractical Tips for Safer C++
19mExploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the(…)
