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@lists.isocpp.org>
Gesendet: Mi 04.11.2026 06:49
Betreff: Re: [std-proposals] noexcept(static)
An: std-proposals@lists.isocpp.org;
CC: Simon Schröder <dr.simon.schroeder@gmail.com>; std-proposals@lists.isocpp.org;


> On Nov 3, 2026, at 10:30 PM, Jonathan Grant via Std-Proposals <std-proposals@lists.isocpp.org> 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals