C++26 Contracts: Pitfalls to Watch Ran
summary
C++26 contracts are ordinary code, so contract functions carry bugs found in real git branches and compiler implementations (GCC/Clang). Examples show a precondition on an empty view that unpredictably fails, const vs non‑const overloads that make code non‑viable, unresolved semantics for virtual/inherited contracts, and preconditions are code. Violation handlers differ by observe/enforce mode; throwing from a handler can bypass destructors and leak memory (demonstrated with Valgrind) leading to noexcept + contract = terminate and hard-to-test behaviors.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 0:24What are contracts
- 1:27Contracts are code too
- 3:56Preconditions on pointers
- 4:58Contract semantics
- 7:13Const vs non-const in contracts
- 12:13Overloaded functions in contracts
- 16:57Contracts on virtual functions
- 18:46Violation handlers
- 20:56Memory leaks from contracts
- 23:10Noexcept libraries and contracts
- 25:47Testing contracts
- 28:53Debugging contracts
- 32:02Common contract mistakes
- 34:09Reflection and contracts
- 36:13Q&A
