C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept(static)

From: Rainer Deyke <rainerd_at_[hidden]>
Date: Tue, 15 Sep 2026 14:22:08 +0200
On 9/15/26 14:01, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Mon, Sep 7, 2026 at 1:59 PM Thiago Macieira wrote:
> I want to go back to first principles of what I intended with
> 'noexcept(static)'. Most basically, where we have code like this:
>
> void Func(void)
> {
> a();
> b();
> c();
> }
>
> I want it to be compiled as follows:
>
> void Func(void)
> {
> static_assert( noexcept( a() ) );
> a();
> static_assert( noexcept( b() ) );
> b();
> static_assert( noexcept( c() ) );
> c();
> }
>
> What complicates this significantly, as you mentioned, is the Lakos
> rule -- i.e. "The throwing of an exception is an acceptable form of
> undefined behaviour". But given the Lakos rule, should "std::sqrt" be
> defined as follows?
>
> double sqrt(double) noexceptLakos;

If a program invokes undefined behavior, then *all* guarantees are off,
including the guarantee that no exception can leave a noexcept function.
  Therefore there is no distinction from the user side between your
proposed noexceptLakos and plain old noexcept.

On the implementation side, there is currently no *standard* way to say
"this exception is allowed to leave this noexcept function, because it
is only thrown when undefined behavior is invoked". However, C++
implementations are free to create a non-standard extension that does
just that.


-- 
Rainer Deyke - rainerd_at_[hidden]

Received on 2026-09-15 12:22:21