From 2ab03a0914023d2150f38fa11c48ddedd90d0c94 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 May 2023 14:42:02 +0200 Subject: [PATCH] util/ScopeExit: allow the function to throw Fixes crash inside AtScopeExit() in the WASAPI output plugin. Closes https://github.com/MusicPlayerDaemon/MPD/issues/1759 --- src/util/ScopeExit.hxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/ScopeExit.hxx b/src/util/ScopeExit.hxx index b64a35cf0..0fecf6c1e 100644 --- a/src/util/ScopeExit.hxx +++ b/src/util/ScopeExit.hxx @@ -47,7 +47,11 @@ public: src.enabled = false; } - ~ScopeExitGuard() { + /* destructors are "noexcept" by default; this explicit + "noexcept" declaration allows the destructor to throw if + the function can throw; without this, a throwing function + would std::terminate() */ + ~ScopeExitGuard() noexcept(noexcept(F::operator()())) { if (enabled) F::operator()(); }