Cpp Contracts - How Contracts in C++26 Can Improve C++ Code Safety and Correctness
summary
Proposal p2900 defines a Contracts MVP for C++26 that adds p2900 function preconditions, postconditions and contract-assert statements, a replaceable contract violation handler (default logs and terminates, user supplyable via link‑time replacement), and four evaluation semantics: ignore, observe, enforce and quick_enforce. The committee counts ~196 distinct use cases, virtual function support and constification remain decided-but-tweaky, and GCC/Clang work is underway; the claim is practical, configurable runtime checks that replace macros without changing language guarantees.
AI-written summary · about
chapters (16)
- 0:00C++ contracts in C++26
- 2:57Why contracts took 20 years
- 7:16What contracts are
- 10:25Contract assertions vs plain language
- 13:15P2900 purpose and design
- 17:27Code examples and operator[] issues
- 22:48Contracts vs assert
- 27:20Pre/post condition semantics
- 31:09Violation handling and customization
- 38:31Three roles in contracts
- 42:01Performance trade-offs
- 45:55Prime directive and side effects
- 48:24Virtual function support
- 52:17Open questions and future
- 57:32Safety, security, correctness
- 1:00:59Q&A
related talks
01h 02mContracts in C++26 - An Insider's Overview
01h 31mContracts for C++
01h 32mContracts for C++
01h 22mContracts, Safety and Correctness in C++
01h 30mContracts, Safety, and the Art of Cat Herding
01h 21mProgramming with Contracts in C++20
01h 17mFunction Contracts in Practice using C++
58mAvoid Misuse of Contracts!
