Skip to content

Commit 72c1982

Browse files
committed
add a unit test
1 parent 9ed5469 commit 72c1982

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/unittests/ADT/FunctionExtrasTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,22 @@ class Incomplete {};
310310
Incomplete incompleteFunction() { return {}; }
311311
const Incomplete incompleteFunctionConst() { return {}; }
312312

313+
// Check that the moved-from captured state is properly destroyed during
314+
// move construction/assignment.
315+
TEST(UniqueFunctionTest, MovedFromStateIsDestroyedCorrectly) {
316+
static int NumOfDestructorsCalled = 0;
317+
struct State {
318+
State() = default;
319+
State(State &&) = default;
320+
State &operator=(State &&) = default;
321+
~State() { ++NumOfDestructorsCalled; }
322+
};
323+
{
324+
unique_function<void()> CapturingFunction{[state = State{}] {}};
325+
unique_function<void()> CapturingFunctionMoved{
326+
std::move(CapturingFunction)};
327+
}
328+
EXPECT_EQ(NumOfDestructorsCalled, 4);
329+
}
330+
313331
} // anonymous namespace

0 commit comments

Comments
 (0)