C++ Logo

std-proposals

Advanced search

Re: proposal: [[noexcept]] attribute

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Wed, 23 Oct 2019 16:47:34 +0300
On 2019-10-23 15:53, Walt Karas via Std-Proposals wrote:
> I propose adding noexcept as an attribute. It would be used after a
> function call to a noexcept(false) function. It asserts that, in that
> context, the function will not throw any exceptions.

noexcept specifier not only documents the function as non-throwing. It
also guarantees that the function won't throw (the program will
terminate if it does). This kind of guarantee cannot be implemented with
an attribute because it is not allowed to have a mandatory behavior.

You could implement what you propose as a library extension:

   template< typename F >
   auto invoke_noexcept(F f) noexcept
   {
     return f();
   }

> I also propose
> that, if a function that only has calls to noexcept functions, or calls
> with the [[noexcept]] attribute, the compiler must emit a diagnostic
> (presumably a warning) if the function is noexcept(false).

That means all current code will suddenly emit tons of warnings. Thanks,
but no.

Received on 2019-10-23 08:49:53