Contracts for C++
summary
A Contracts MVP is approved for C++26 and ships as C++26 Contracts MVP providing three assertion kinds: contract_assert plus pre/post function assertions on declarations, a new <contract> API with contract_violation (location, semantic, exception_ptr) and a replaceable global handler, and four evaluation semantics (ignore, observe, enforce, quick_enforce). GCC and Clang have working implementations on Compiler Explorer (see paper P33460), compilers control semantics per TU or runtime, and roadmap items (always-enforce, implicit checks, captures, virtual/post rules) target C++29.
AI-written summary · about
chapters (8)
- 0:00C++26 contract assertions intro
- 10:20What contracts replace
- 21:14C++26 contracts roadmap
- 29:52Design by contract history
- 45:06Why contracts took 21 years
- 1:01:20Writing contract assertions rules
- 1:12:50Contracts and undefined behavior
- 1:20:16Future directions for contracts
related talks
01h 31mContracts for C++
01h 03mCpp Contracts - How Contracts in C++26 Can Improve C++ Code Safety and Correctness
01h 02mContracts in C++26 - An Insider's Overview
57mPerspectives on Contracts for C++
01h 30mContracts, Safety, and the Art of Cat Herding
56mContracts for Dependable C++
01h 21mProgramming with Contracts in C++20
01h 05m“Contract Programming in C++(20) (part 2 of 2)”
