File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -313,19 +313,22 @@ const Incomplete incompleteFunctionConst() { return {}; }
313
313
// Check that the moved-from captured state is properly destroyed during
314
314
// move construction/assignment.
315
315
TEST (UniqueFunctionTest, MovedFromStateIsDestroyedCorrectly) {
316
+ static int NumOfMovesCalled = 0 ;
316
317
static int NumOfDestructorsCalled = 0 ;
317
318
struct State {
318
319
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)}; }
321
324
~State () { ++NumOfDestructorsCalled; }
322
325
};
323
326
{
324
327
unique_function<void ()> CapturingFunction{[state = State{}] {}};
325
328
unique_function<void ()> CapturingFunctionMoved{
326
329
std::move (CapturingFunction)};
327
330
}
328
- EXPECT_EQ (NumOfDestructorsCalled, 4 );
331
+ EXPECT_EQ (NumOfDestructorsCalled, 1 + NumOfMovesCalled );
329
332
}
330
333
331
334
} // anonymous namespace
You can’t perform that action at this time.
0 commit comments