diff --git a/src/util/ScopeExit.hxx b/src/util/ScopeExit.hxx index c6278a977..9e1cc5dde 100644 --- a/src/util/ScopeExit.hxx +++ b/src/util/ScopeExit.hxx @@ -10,14 +10,18 @@ * Internal class. Do not use directly. */ template -class ScopeExitGuard : F { +class ScopeExitGuard { + [[no_unique_address]] + F function; + bool enabled = true; public: - explicit ScopeExitGuard(F &&f) noexcept:F(std::forward(f)) {} + explicit ScopeExitGuard(F &&f) noexcept + :function(std::forward(f)) {} ScopeExitGuard(ScopeExitGuard &&src) noexcept - :F(std::move(src)), + :function(std::move(src.function)), enabled(std::exchange(src.enabled, false)) {} /* destructors are "noexcept" by default; this explicit @@ -26,7 +30,7 @@ public: would std::terminate() */ ~ScopeExitGuard() noexcept(noexcept(std::declval()())) { if (enabled) - F::operator()(); + function(); } ScopeExitGuard(const ScopeExitGuard &) = delete;