C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept has gotten a bit hairy -- I want a compiler error

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 05 May 2025 20:35:22 -0700
On Monday, 5 May 2025 17:57:35 Pacific Daylight Time Jason McKesson via Std-
Proposals wrote:
> Within the context of the bad idea under discussion, that wouldn't
> really work. After all, C functions are technically "noexcept" but
> they aren't labeled as such, so such code would be unable to call
> them. Furthermore, the committee's rules for when non-throwing
> functions should be marked `noexcept` don't match with the needs of
> the proposed feature.

Except, in reality, no they aren't. C functions can unwind the stack through
either setjmp/longjmp, directly via libunwind, or via pthread_cancel. Plus if
were to apply Lakos Rule to all functions, many of those C functions (not in
the C or math libraries) would not be noexcept because they have narrow
contracts.

> > If you really need this, just wrap them in an noexcept IILE. If they don't
> > throw, this has cost you a few bytes in the exception handling table. If
> > they do throw, you'll abort at runtime.
>
> That wouldn't work with the idea in question (which again, is a *bad*
> idea). If `noexcept` functions fail to compile if they invoke a
> non-`noexcept` function, you can't just wrap them, as the wrapper
> would fall prey to the same problem. You need a way to pretend that a
> non-`noexcept` function is `noexcept`.

That's a different problem. I was looking into the noexcept_cast + wont_throw
ideas.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-05-06 03:35:28