C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Lakos rule

From: Tom Honermann <tom_at_[hidden]>
Date: Thu, 21 Dec 2023 12:49:53 -0500
The Lakos rule is important as a means to allow what would otherwise be
undefined behavior to (in some cases) produce a thrown exception. This
allows, for example, a function to throw an exception upon detection of
a precondition violation. This can be desirable as a bug detection
mechanism in debug builds but where such detection is not desirable for
production builds due to overhead. See also Ville's response regarding
contracts.

You might also be interested in P2946 (A Flexible Solution to the
Problems of noexcept) <https://wg21.link/p2946>.

Tom.

On 12/21/23 7:39 AM, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> I see people arguing that the Lakos rule should be kept, and others
> saying it should be abolished.
>
> For everyone to meet half way, what if the Standard library could do:
>
> namespace std {
> int SomeFunc(int,int) noexcept_Lakos;
> }
>
> A function marked as 'noexcept_Lakos' is said to be a 'Lakos function'.
>
> So then if you want a Lakos function to be 'noexcept', you do
> something like:
>
> void MyFunc(int const a, int const b) noexcept
> {
> using noexcept_Lakos;
> // The above line ensures that all
> // Lakos functions called in this
> // function won't throw
> return 2 * std::SomeFunc(a,b);
> }
>
> Or if you just want to single-out one function call:
>
> void MyFunc(int const a, int const b) noexcept
> {
> return 2 * _Lakos(std::SomeFunc(a,b));
> }
>
>

Received on 2023-12-21 17:49:55