From 8c165a4199aee2f300ff4b4958e4842af0043c19 Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:50:24 -0500 Subject: [PATCH] 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. --- include/gsl/util | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/gsl/util b/include/gsl/util index 6e29894..597f35c 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -73,6 +73,8 @@ using index = std::ptrdiff_t; template class final_action { + static_assert(std::is_nothrow_invocable_v, "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)} { }