P4011R0 — Redefining narrow contract (4 items) EWG
Matthias Kretz
This paper identifies a problem with the existing definitions of narrow and wide contracts, which are defined in terms of undefined behavior: unconditionally enforced precondition checks can inadvertently make a function appear to have a wide contract by eliminating UB. It proposes a revised definition where a function has a narrow contract if there exists at least one input for which the call is erroneous, decoupling the concept from undefined behavior. This allows the distinction between narrow and wide contracts to remain meaningful in the presence of contract enforcement mechanisms like those proposed in P2900.

References — Anthropic Citations API

[1]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. "
[1]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. "
[1]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. [N3248] defined the terms narrow and wide contract in terms of undefined..."
[2]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. "
[2]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. "
[2]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. [N3248] defined the terms narrow and wide contract in terms of undefined..."
[3]
"P4011R0 1 Changelog 1 CHANGELOG (placeholder) 2 STRAW POLLS (placeholder) 3 THE PROBLEM Meredith et al. [N3248] defined the terms narrow and wide contract in terms of undefined..."
Summary: Proposes replacing the current definition of narrow contract with a formulation that separates precondition violation from undefined behavior, aiming to let implementations choose between UB, erroneous behavior, or contract-violation handling when preconditions are not met.
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.