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: Sat, 10 May 2025 17:47:05 +0200
On Saturday, 10 May 2025 12:40:16 Central European Summer Time Simon Schröder
via Std-Proposals wrote:
> Concerning C functions: Would it make sense to automatically declare all
> ‘extern “C”’ functions noexcept? Or is this something that is already
> allowed for compilers to assume? It might be a bad idea if someone provides
> a C interface for a C++ implementation, though.

No, and no. This would be a terrible idea.

You can declare C++ functions with an extern "C" interface, so they could
throw just fine. In fact, there are some C libraries that are implemented in
C++ including a full C standard library runtime (UCRT).

Moreover, C++ is not the only way that an exception/stack unwinding is
possible. The GNU libc marks its C libraries as throwing or non-throwing
depending on whether they are PThread cancellation points. This is the state
of the art. All other C libraries should just be upgraded to mark noexcept
too. Anything else is a QoI problem and you can complain to your vendor.

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

Received on 2025-05-10 15:47:09