P4015R0 — Enforcing Contract Conditions with Statements (9 items) Evolution Working Group
Lisa Lippincott
This paper explores a design direction for C++26 contracts where enforcement behavior is specified through statements within function bodies rather than within declarations. The core insight is that placing enforcement semantics in declarations turns agreed-upon rules into 'offers' that optimizers can exploit, potentially introducing vulnerabilities when library implementations change. The paper proposes novel statements (enforce_preconditions, enforce_postconditions_on_return, enforce_preconditions_on_call, enforce_postconditions_on_call) that separate the agreement on conditions from their enforcement, though the author explicitly states this is informational and does not advocate for adoption in C++26 or C++29.

References — Anthropic Citations API

[1]
"// foo.h #include extern char foo_buffer[64]; void foo( char[] text, std::size_t text_length ) always_enforced_pre( text_length <= sizeof(foo_buffer) ); By using always_enforced_pre..."
[2]
"enforce_return_condition_statement: enforce_condition_on_return ( result-name-introduceropt conditional-expression ) ;"
[3]
"enforce_postconditions_statement: enforce_postconditions_on_return ;"
[4]
"Like enforce_preconditions and enforce_postconditions, these statements perform contract enforcement"
[5]
"Document: P4015r0 Date: 2026-02-16 Reply-to: Lisa Lippincott Audience: Evolution Working Group Enforcing Contract Conditions with Statements Lisa..."
Summary: P4015R0 proposes a set of enforcement statements (enforce_condition, enforce_preconditions, enforce_condition_on_return, enforce_postconditions_on_return) that allow callers to opt into always-checked contract conditions at the call site, independent of the build mode used to compile the callee. Five items were found: two grammar production naming inconsistencies, one reference to a nonexistent identifier, a likely incorrect document date, and a typo.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.