Keynote: Contracts, Testing & the Pursuit of Well Defined Behaviour
summary
Shows that language-level preconditions and a small Contracts MVP (pre/post/assert) aim for C++26, with an implementation model that supports enforce/observe/ignore semantics and a replaceable violation handler (prints diagnostics or throws for test harnesses). Documents how UB (off-by-one, signed overflow) gets optimized away, how assume (available in C++23/GCC13) yields faster code, and why testing contracts uses exceptions not noexcept and why death tests or fork/spawn hacks are impractical. Explains tradeoffs and tool interactions (UBSan, sanitizers, static analysis).
AI-written summary · about
chapters (42)
- 0:00Introduction to safety
- 2:37Understanding UB
- 5:35How UB affects compilation
- 6:43Concrete examples of UB
- 10:10Mitigating UB risks
- 12:12The trade-offs of safety
- 14:20Language evolution strategies
- 18:39Current safety proposals
- 21:35Introduction to contracts
- 23:53Narrow vs wide contracts
- 26:12Analyzing Vector contracts
- 28:46Soft vs hard UB
- 31:28Implementing contract checks
- 34:22Contract semantics
- 36:44The 'assume' semantic
- 37:43C++23 assume attribute
- 39:56Assume in production
- 42:51Assume benchmarks
- 44:23Contract kinds
- 46:22Testing postconditions
- 48:45Class invariants
- 50:09Contracts vs unit testing
- 52:21Testing precondition checks
- 55:09Exception-based testing
- 57:05The noexcept conflict
- 58:53The Lakers rule
- 1:00:53Purpose of noexcept
- 1:02:13Debating noexcept usage
- 1:04:14Workarounds for testing
- 1:06:13Death tests
- 1:09:09Final recommendations
- 1:12:31Noexcept code gen
- 1:14:04Future of noexcept
- 1:15:25Standardizing contracts
- 1:17:18History of proposals
- 1:19:20SG21 and the MVP
- 1:21:18Contract MVP features
- 1:23:32Build modes
- 1:25:25Violation handler
- 1:27:09Future contract applications
- 1:29:38Contract syntax debate
- 1:32:39Looking ahead
related talks
37mContracts For Getting More Programs Less Wrong
59mC++ Unit testing - the good, the bad & the ugly
01h 02mBack to Basics: C++ Testing
01h 01mBack to Basics: Test-driven Development
01h 40mTesting, Preconditions, Coverage and Templates in Safety-Critical C++ Code
01mC++ On Sea 2024 Preview: Testable by Design
53mC++ Unit testing - the good, the bad & the ugly
56mWill Your C++ Program Still Be Correct Next Year?
