File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -310,4 +310,22 @@ class Incomplete {};
310
310
Incomplete incompleteFunction () { return {}; }
311
311
const Incomplete incompleteFunctionConst () { return {}; }
312
312
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
+
313
331
} // anonymous namespace
You can’t perform that action at this time.
0 commit comments