Merge pull request #117 from trebconnell/finalact

Fix moving a final_act twice
This commit is contained in:
Neil MacIntosh 2015-10-02 16:28:29 -07:00
commit f0262f5099
2 changed files with 8 additions and 3 deletions

View File

@ -80,7 +80,7 @@ class final_act
public: public:
explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} 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(const final_act&) = delete;
final_act& operator=(const final_act&) = delete; final_act& operator=(const final_act&) = delete;

View File

@ -44,9 +44,14 @@ SUITE(utils_tests)
auto _1 = finally([&]() {f(i);}); auto _1 = finally([&]() {f(i);});
{ {
auto _2 = std::move(_1); 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); CHECK(i == 1);
} }