From 8ffd43043d0c10c4a6067a3efbab861ed67139d0 Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:01:15 -0500 Subject: [PATCH 1/4] allow final action to invoke throwing actions where an action is provided to final action to execute at end of scope and that action throws, because final action's destructor is marked noexcept, the program will terminate. Instead, allow final action's destructor to be noexcept dependent upon whether the action throws. --- include/gsl/util | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gsl/util b/include/gsl/util index fb7572e..b7baf20 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -77,7 +77,7 @@ public: explicit final_action(const F& ff) noexcept : f{ff} { } explicit final_action(F&& ff) noexcept : f{std::move(ff)} { } - ~final_action() noexcept { if (invoke) f(); } + ~final_action() noexcept(std::is_nothrow_invocable_v) final_action(final_action&& other) noexcept : f(std::move(other.f)), invoke(std::exchange(other.invoke, false)) From 628b2c5c278227538c925bb5c1ab8a6d0bdec031 Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:07:56 -0500 Subject: [PATCH 2/4] Update headers.md --- docs/headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/headers.md b/docs/headers.md index 96465a3..c41d49b 100644 --- a/docs/headers.md +++ b/docs/headers.md @@ -808,7 +808,7 @@ explicit final_action(F&& ff) noexcept; Construct an object with the action to invoke in the destructor. ```cpp -~final_action() noexcept; +~final_action() noexcept(std::is_nothrow_invocable_v); ``` The destructor will call the action that was passed in the constructor. From e00c1ccf55082faf7cd1ca4891659a49320aa018 Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:22:26 -0500 Subject: [PATCH 3/4] fix syntax --- include/gsl/util | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gsl/util b/include/gsl/util index b7baf20..9f0a46f 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -77,7 +77,7 @@ public: explicit final_action(const F& ff) noexcept : f{ff} { } explicit final_action(F&& ff) noexcept : f{std::move(ff)} { } - ~final_action() noexcept(std::is_nothrow_invocable_v) + ~final_action() noexcept(std::is_nothrow_invocable_v){ } final_action(final_action&& other) noexcept : f(std::move(other.f)), invoke(std::exchange(other.invoke, false)) From 49371c5f298707209c5f947bec747558bcd955a6 Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:24:21 -0500 Subject: [PATCH 4/4] syntax fix --- include/gsl/util | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gsl/util b/include/gsl/util index 9f0a46f..443f112 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -77,7 +77,7 @@ public: explicit final_action(const F& ff) noexcept : f{ff} { } explicit final_action(F&& ff) noexcept : f{std::move(ff)} { } - ~final_action() noexcept(std::is_nothrow_invocable_v){ } + ~final_action() noexcept(std::is_nothrow_invocable_v) { if (invoke) f(); } final_action(final_action&& other) noexcept : f(std::move(other.f)), invoke(std::exchange(other.invoke, false))