Contracts in C++26 - An Insider's Overview
summary
After two decades of work the Contracts MVP is confirmed for C++26 (P2900 with rationale P2899) and specifies concrete syntax like pre(...) for preconditions, contract assert as a statement (not an expression), and postconditions that can name the return value. It bans lambdas in repeated contracts, requires const for by-value parameters ODR-used in postconditions, and defines four semantics (observe/enforce/quick_enforce/ignore) plus a replaceable link‑time handler handle_contract_violation. Implementations may evaluate assertions multiple times or elide them.
AI-written summary · about
chapters (14)
- 0:00C++26 contracts intro
- 10:15Contracts terms and types
- 13:52Constification controversy
- 23:06Post conditions and returns
- 27:46Post param const limits
- 28:07Contract evaluation order
- 31:19Contract evaluation semantics in detail
- 36:21Semantics selection freedom
- 39:10Elision and side effects
- 44:48Violation handlers role
- 51:17Exceptions in handlers
- 54:13noexcept and assertions
- 57:25Assert as statement vs expr
- 59:13Summary and future
related talks
01h 03mCpp Contracts - How Contracts in C++26 Can Improve C++ Code Safety and Correctness
01h 31mContracts for C++
01h 32mContracts for C++
57mPerspectives on Contracts for C++
01h 05m“Contract Programming in C++(20) (part 2 of 2)”
01h 03m“Contract Programming in C++(20) (part 1 of 2)”
01h 21mProgramming with Contracts in C++20
56mContracts for Dependable C++
