Skip to content

Commit 0442dbd

Browse files
committed
refactor the test
1 parent 72c1982 commit 0442dbd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/unittests/ADT/FunctionExtrasTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,22 @@ const Incomplete incompleteFunctionConst() { return {}; }
313313
// Check that the moved-from captured state is properly destroyed during
314314
// move construction/assignment.
315315
TEST(UniqueFunctionTest, MovedFromStateIsDestroyedCorrectly) {
316+
static int NumOfMovesCalled = 0;
316317
static int NumOfDestructorsCalled = 0;
317318
struct State {
318319
State() = default;
319-
State(State &&) = default;
320-
State &operator=(State &&) = default;
320+
State(const State &) = delete;
321+
State(State &&) { ++NumOfMovesCalled; }
322+
State &operator=(const State &) = delete;
323+
State &operator=(State &&Rhs) { return *new (this) State{std::move(Rhs)}; }
321324
~State() { ++NumOfDestructorsCalled; }
322325
};
323326
{
324327
unique_function<void()> CapturingFunction{[state = State{}] {}};
325328
unique_function<void()> CapturingFunctionMoved{
326329
std::move(CapturingFunction)};
327330
}
328-
EXPECT_EQ(NumOfDestructorsCalled, 4);
331+
EXPECT_EQ(NumOfDestructorsCalled, 1 + NumOfMovesCalled);
329332
}
330333

331334
} // anonymous namespace

0 commit comments

Comments
 (0)