From f59cb795a0fec46f20bc66262bdbb3f05551137e Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Wed, 24 Feb 2021 16:42:58 -0800 Subject: [PATCH] Figured out test failures, removed move test We shouldn't be moving these `final_action`s around, that wasn't part of the C++CG design requirements. Went back to the simple version of `final_action`. --- include/gsl/util | 10 +++++----- tests/utils_tests.cpp | 19 ------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/include/gsl/util b/include/gsl/util index f853777..ebaeef6 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -52,14 +52,14 @@ template class final_action { public: - explicit final_action(F f) : f_(std::move(f)) { } - ~final_action() { f_(); } + explicit final_action(F f_) : f(f_) { } + ~final_action() { f(); } - final_action(const final_action&) = default; - final_action& operator=(const final_action&) = default; + final_action(const final_action& rhs) = delete; + final_action& operator=(const final_action&) = delete; private: - F f_; + F f; }; // finally() - convenience function to generate a final_action diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 74dc990..705f384 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -51,25 +51,6 @@ TEST(utils_tests, finally_lambda) EXPECT_TRUE(i == 1); } -TEST(utils_tests, finally_lambda_move) -{ - int i = 0; - { - auto _1 = finally([&]() { f(i); }); - { - auto _2 = std::move(_1); - EXPECT_TRUE(i == 0); - } - EXPECT_TRUE(i == 1); - { - auto _2 = std::move(_1); - EXPECT_TRUE(i == 1); - } - EXPECT_TRUE(i == 1); - } - EXPECT_TRUE(i == 1); -} - TEST(utils_tests, finally_const_lvalue_lambda) { int i = 0;