C++ Pitfalls and Sharp Edges to Avoid
summary
A string of concrete traps and fixes: a missing non-void return causes a timer callback to silently reschedule in production; a stray semicolon makes an if always execute; the comma operator plus default args silently misinitialize a Point; returning a reference from get_or_default yields a dangling ref; shared_ptr cycles leak; moved-from objects and SSO produce intermittent bugs; unspecified evaluation order breaks assumptions. Recommended tooling and settings: -Wall -Wextra -Wnull, use static analyzers and clang-tidy, run address/UB/runtime sanitizers both with and without optimization, plus strict code review and targeted refactors.
AI-written summary · about
chapters (25)
- 0:00Introduction to C++ pitfalls
- 2:04Should we check for null
- 3:10Story of a production bug
- 7:00Essence vs accidental bugs
- 10:30Common accidental bugs in C++
- 13:01Safety nets for bug prevention
- 18:46Compiler warnings and static analysis
- 23:55Undefined behavior examples
- 25:44Dangling references in code
- 28:14Recurring bugs and solutions
- 30:44Polymorphism pitfalls
- 34:43Object slicing issues
- 35:49Memory leaks and cycles
- 37:38Dead stack variables
- 41:14Shadowing and variable scope
- 42:43Dangling references from moves
- 46:47Static initialization pitfalls
- 49:24Complex code and refactoring
- 53:23Unmaintainable code dangers
- 55:52State machines for clarity
- 59:30API assumptions and facades
- 1:05:17Invalidated iterators
- 1:07:47C++ language complexity
- 1:11:01Summary and best practices
- 1:18:30Q&A session
