enforcement for no-throw finally actions

a throwing finally action will be accepted by the compiler but result in surprise termination at runtime; enforce that actions provided to finally must be non-throwing at compile time.
This commit is contained in:
apenn-msft 2025-02-03 17:50:24 -05:00 committed by GitHub
parent 5a66c65d09
commit 8c165a4199
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -73,6 +73,8 @@ using index = std::ptrdiff_t;
template <class F>
class final_action
{
static_assert(std::is_nothrow_invocable_v<F>, "the provided action must be non-throwing");
public:
explicit final_action(const F& ff) noexcept : f{ff} { }
explicit final_action(F&& ff) noexcept : f{std::move(ff)} { }