From d74fca4e9820e836fb5a815062a254d93d69ecc9 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 18 Jun 2018 13:51:59 +1000 Subject: [PATCH] scoped: simplify universal references this avoids problems with use after stack unwind discovered using sanitizers. --- scoped.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scoped.hpp b/scoped.hpp index 31f2544e..94de6a21 100644 --- a/scoped.hpp +++ b/scoped.hpp @@ -16,6 +16,8 @@ #pragma once +#include + namespace util::scoped { /////////////////////////////////////////////////////////////////////////// @@ -78,12 +80,8 @@ namespace util::scoped { template class function { public: - explicit function (FuncT &&_function, Args&& ..._args) - noexcept ( - std::is_nothrow_move_constructible_v && - std::is_nothrow_move_constructible_v> - ): - m_function (std::move (_function)), + explicit function (FuncT &&_function, Args&& ..._args): + m_function (std::forward (_function)), m_args (std::forward (_args)...) { ; } @@ -93,7 +91,7 @@ namespace util::scoped { ~function () { if (m_enabled) - std::apply (std::move (m_function), std::move (m_args)); + std::apply (m_function, m_args); } void disable (void) { m_enabled = false; } @@ -107,5 +105,5 @@ namespace util::scoped { //------------------------------------------------------------------------- template - function (FuncT &&, Args&&...) -> function; + function (FuncT,Args...) -> function; };