From 7e6d025540f03b4df8700e363229c6dd88b4886d Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Thu, 25 Jan 2018 16:55:48 +0000 Subject: Give scope_exit helper correct move semantics llvm-svn: 323442 --- llvm/unittests/ADT/ScopeExitTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'llvm/unittests/ADT/ScopeExitTest.cpp') diff --git a/llvm/unittests/ADT/ScopeExitTest.cpp b/llvm/unittests/ADT/ScopeExitTest.cpp index 301942c30bb..ab11dff8ce4 100644 --- a/llvm/unittests/ADT/ScopeExitTest.cpp +++ b/llvm/unittests/ADT/ScopeExitTest.cpp @@ -29,4 +29,21 @@ TEST(ScopeExitTest, Basic) { EXPECT_TRUE(Called); } +TEST(ScopeExitTest, Release) { + int Count = 0; + auto Increment = [&] { ++Count; }; + { + auto G = make_scope_exit(Increment); + auto H = std::move(G); + auto I = std::move(G); + EXPECT_EQ(0, Count); + } + EXPECT_EQ(1, Count); + { + auto G = make_scope_exit(Increment); + G.release(); + } + EXPECT_EQ(1, Count); +} + } // end anonymous namespace -- cgit v1.2.3