C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Using [[assume]] attribute in contracts pre() and post() blocks

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 24 Aug 2026 16:21:43 +0300
On Mon, 24 Aug 2026 at 16:16, David Brown via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Having a convenient way to "assume" that contracts hold would definitely
> be useful. I am not sure what the best syntax would be (or to be more
> honest, I haven't a clue about the best syntax), but what I would like
> to see is a way to do:
>
> 1. In the function's declaration, say that the caller must check the
> pre-condition.
>
> 2. In the function's declaration, say that the caller can assume the
> post-condition holds when optimising.
>
> 3. Let the function implementation assume the pre-condition holds. This
> could be either as a general "it always holds" indication, but might be
> better as a "assume pre-conditions hold at this point in the function
> implementation". That could allow certain specific checks before the
> assumption.
>
> 4. Let callers and callees override or dictate the contract enforcement
> semantics, and do so separately for pre and post conditions.

I can tweak https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4324r0.html
to do all that.

Received on 2026-08-24 13:22:01