C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept(static)

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Thu, 5 Nov 2026 06:43:47 +0100
These are all good points. In general, I’d want the best performance possible. That would include that if the compiler can prove that a precondition is always fulfilled, the runtime check can be left out. However, I would also not entirely trust the compiler (bugs in the compiler can happen). Especially for debugging (or safety conscious applications) I would want the maximum checks possible. It would be nice if compilers provided options to switch between all 3 levels (static checks eliminate runtime checks, caller-side checking, and both caller and callee checking).

We have additional problems if we have checks at both the caller and the callee: It might get confusing if they have different failure semantics, e.g. if the caller uses observe and the callee uses terminate.

> On Nov 4, 2026, at 10:39 AM, Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
> Yes, contracts don't replace input validations and still error handling has to be put in.
>
> However stay with me.
>
>
>
> Normally
>
> - We assume pre-condition are to be checked or ensured by the caller
>
> - For performance reasons they could be left out to be checked or even assumed to be true in the callee
>
> - If they are violated, it is a logical program error, we have to assume more went wrong, so it is not recoverable
>
>
>
> Now let's harden it (the same source code)
>
> - We (automatically) recheck all pre-conditions in the callee [and optionally automatically in the caller, too, but that is not the scope of this mail]
>
> - We don't assume the stated pre-conditions to be true, before checking
>
> - We either try to handle the error as gracefully as possible, so either returning an error code, a std:excepted type with unexpected value or throw an exception (before an optional returning handler could be called for error logging or error display)
>
> - Or we detect the error, but directly terminate or call a fault handler, which terminates
>
>
>
> Should contracts only support the first semantics, or only the second semantics or optionally both? Or allow even a mixture? If there are no bugs, both work equally (minus performance). If there are bugs, the second semantics would be better at detecting them and have more options to handle them. The first semantics is clearer about the responsibilities, but may be incompatible with some industries or component interface boundaries. Regulatory requirements or risk reduction measures may demand that certain invariants and pre-conditions are rechecked at those boundaries to allow stricter local reasoning and more determinism. [What if the optimizer proves them to be always true, is it allowed to remove the checks?] Should the contracts feature be used in such cases?
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Simon Schröder via Std-Proposals <std-proposals_at_[hidden]>
> Gesendet: Mi 04.11.2026 06:49
> Betreff: Re: [std-proposals] noexcept(static)
> An: std-proposals_at_[hidden];
> CC: Simon Schröder <dr.simon.schroeder_at_[hidden]>; std-proposals_at_[hidden];
>
>
> > On Nov 3, 2026, at 10:30 PM, Jonathan Grant via Std-Proposals <std-proposals_at_[hidden]> wrote:
> >
> > It feels like C++ Contracts should not be used for this, a regular check that there is enough buffer space should be added, and an exception thrown or error code returned instead.
>
> I think this hits the nail on the head: Contracts don’t replace input validation.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-11-05 05:44:05