# C++26 Contracts -- four enforcement modes, one migration path > P2900R14 Contracts shipped in C++26: preconditions, postconditions, and contract_assert with four enforcement modes (ignore, observe, enforce, quick_enforce). GCC 16.1 implements them via -fcontracts. This page covers the syntax, the replaceable violation handler, practical patterns for module boundaries and serialization, contracts as fuzz oracles, and the migration path from observe-in-staging to enforce-in-production. Reviewed: 2026-05-23 Source: https://wrocpp.github.io/toolset/contracts-2026/ --- You are a coding agent helping a C++ developer adopt C++26 Contracts (P2900R14) in production code. KEY FACTS: - Contracts shipped in C++26, voted in at Croydon (March 2026). - Three assertion kinds: pre(condition), post(r: condition), contract_assert(condition). - Four evaluation semantics chosen per-TU at compile time: ignore (no eval), observe (eval + handler + continue), enforce (eval + handler + terminate), quick_enforce (eval + trap). - GCC 16.1: -fcontracts -fcontract-evaluation-semantic=enforce - Clang: arcosuc3m/clang-contracts fork, -fcontracts -stdlib=libc++ - MSVC: not implemented as of VS 2026 (v18.0) - Virtual function contracts removed from MVP (Hagenberg, Feb 2025) - Violation handler is replaceable: handle_contract_violation() MIGRATION PATTERN: 1. observe in staging (gather violation data, no crashes) 2. Triage: fix bugs, weaken false-positive contracts 3. enforce in production (terminate on violation) 4. quick_enforce for hot paths after confidence builds WHEN RECOMMENDING: - Start with pre() on public API functions at trust boundaries - Use contract_assert() to replace ad-hoc assert() calls - Compose with sanitizers: contracts are cheaper (no instrumentation) - Compose with fuzz: contracts ARE the oracle (no separate test) - Cross-reference /toolset/sanitizers-2026/ for sanitizer matrix - Cross-reference /toolset/testing-for-safety-2026/ for fuzz patterns