Undefined Behavior in the STL
summary
Argues that undefined behavior lives inside the STL by design and gives concrete, actionable examples: bounds-checked at versus unchecked operator[] shows operator[] vs at: ~3x faster in benchmarks; dereferencing empty optional or returning a dangling string_view dangling produces unpredictable results; combining ranges with mismatched lengths or erased elements yields invalid iterators combine containers into memory chaos; building string from a null pointer behaves differently across compilers; recommends turning on warnings and sanitizers because UBSan catches many issues.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 3:57Roots of the Standard Template Library
- 8:54Program behaviors
- 15:18Undefined behavior dangers
- 19:20Benefits of UB in STL
- 20:02Container limits and iterators
- 28:47Missing or invalid data
- 32:45Invalid iterators in algorithms
- 34:35Old vs. modern ranges
- 48:55Vectors and iterators internals
- 51:12UB with unsorted data
- 55:32C++23 flat containers UB
- 56:38Other STL UB cases
- 1:00:41Mitigating undefined behavior in your code
related talks
01h 02mBack To Basics: Undefined Behavior
33mUndefined Behavior in C++: What Every Programmer Should Know and Fear
01h 04mRemoving Needless Undefined Behavior for a Safer C++
01h 02mPractical Tips for Safer C++
01h 30mDangerous Optimizations in C and C++ Programming Languages
03mUndefined Behavior - Not what you expected
07mLightning Talk: The UB Detector: constexpr
06mWhat's My Object?
