C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept(override) and maybe noexcept(auto)?

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Fri, 23 Aug 2024 10:18:43 +0200
On 23/08/2024 10.09, Robin Savonen Söderholm via Std-Proposals wrote:
> Hi!
>
> Feels like I am spamming this mailing list, please tell me if you think that I throw ideas at you at a too immature phase...
>
> But I just recently got a compilation error when running my code through gcc after it been developed with MSVC about noexcept-specifier (or rather lack-of).
> It is about the std::exception::what() in this case, that is marked with `noexcept` with GNU c++ library, but not with MSVC:s (2022) library.

And that's a bug with MSVC. Please report that so that it can get fixed.

[exception] clearly shows that the "what()" member is declared "noexcept".

> I solved the issue for now by using the noexcept-operator, doing `noexcept(noexcept(std::exception::what()))`, but I think that a nice syntax that could be used in such cases are `noexcept(override)` to "copy" the exception specifier of the overridden function (yet again, maybe MSVC should not issue a warning if the overriding function has a more relaxed exception specifier than that of the overridden function).

See above; that's a non-problem for your specific example.

> I also think that a `noexcept(auto)` or just simply having an implicit noexcept on inline/constexpr function if all calls inside the function are noexcept would be nice to have as well, due to the fact that sometimes we do specific stuff based upon the exception specifier to have certain exception guarantees that we can skip if everything we are dependent on is noexcept. The compiler should be able to check all operations and function-calls inside a function to determine what exception specification could be used, where we can specify things manually if we somehow can make certain guarantees as well.

We had noexcept(auto) proposal(s) in the past that went nowhere.
I have no details to offer, though.

Jens

Received on 2024-08-23 08:18:46