From b8ec73a1790fb682037d6f5ca7109e7d5dfddb06 Mon Sep 17 00:00:00 2001 From: Treb Connell Date: Fri, 2 Oct 2015 15:58:23 -0700 Subject: [PATCH] Fix moving a final_act twice --- include/gsl.h | 2 +- tests/utils_tests.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/gsl.h b/include/gsl.h index dd3d971..824ca6a 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -80,7 +80,7 @@ class final_act public: explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} - final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(true) { other.invoke_ = false; } + final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(other.invoke_) { other.invoke_ = false; } final_act(const final_act&) = delete; final_act& operator=(const final_act&) = delete; diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 3090c7d..9406e6b 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -44,9 +44,14 @@ SUITE(utils_tests) auto _1 = finally([&]() {f(i);}); { auto _2 = std::move(_1); - CHECK(i == 0); + CHECK(i == 0); } - CHECK(i == 1); + CHECK(i == 1); + { + auto _2 = std::move(_1); + CHECK(i == 1); + } + CHECK(i == 1); } CHECK(i == 1); }