File tree Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 10
10
11
11
using namespace llvm ;
12
12
13
+ int CountCopyAndMove::Constructions = 0 ;
13
14
int CountCopyAndMove::CopyConstructions = 0 ;
14
15
int CountCopyAndMove::CopyAssignments = 0 ;
15
16
int CountCopyAndMove::MoveConstructions = 0 ;
Original file line number Diff line number Diff line change 12
12
namespace llvm {
13
13
14
14
struct CountCopyAndMove {
15
+ static int Constructions;
15
16
static int CopyConstructions;
16
17
static int CopyAssignments;
17
18
static int MoveConstructions;
18
19
static int MoveAssignments;
19
20
static int Destructions;
20
21
int val;
21
22
22
- CountCopyAndMove () = default ;
23
- explicit CountCopyAndMove (int val) : val(val) {}
23
+ CountCopyAndMove () { ++Constructions; }
24
+ explicit CountCopyAndMove (int val) : val(val) { ++Constructions; }
24
25
CountCopyAndMove (const CountCopyAndMove &other) : val(other.val) {
25
26
++CopyConstructions;
26
27
}
@@ -40,13 +41,18 @@ struct CountCopyAndMove {
40
41
~CountCopyAndMove () { ++Destructions; }
41
42
42
43
static void ResetCounts () {
44
+ Constructions = 0 ;
43
45
CopyConstructions = 0 ;
44
46
CopyAssignments = 0 ;
45
47
MoveConstructions = 0 ;
46
48
MoveAssignments = 0 ;
47
49
Destructions = 0 ;
48
50
}
49
51
52
+ static int TotalConstructions () {
53
+ return Constructions + MoveConstructions + CopyConstructions;
54
+ }
55
+
50
56
static int TotalCopies () { return CopyConstructions + CopyAssignments; }
51
57
52
58
static int TotalMoves () { return MoveConstructions + MoveAssignments; }
Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " llvm/ADT/FunctionExtras.h"
10
+ #include " CountCopyAndMove.h"
10
11
#include " gtest/gtest.h"
11
12
12
13
#include < memory>
@@ -332,20 +333,15 @@ TEST(UniqueFunctionTest, InlineStorageWorks) {
332
333
// Check that the moved-from captured state is properly destroyed during
333
334
// move construction/assignment.
334
335
TEST (UniqueFunctionTest, MovedFromStateIsDestroyedCorrectly) {
335
- static int NumOfMovesCalled = 0 ;
336
- static int NumOfDestructorsCalled = 0 ;
337
- struct State {
338
- State () = default ;
339
- State (State &&) { ++NumOfMovesCalled; }
340
- ~State () { ++NumOfDestructorsCalled; }
341
- };
336
+ CountCopyAndMove::ResetCounts ();
342
337
{
343
- unique_function<void ()> CapturingFunction{[state = State{}] {}};
338
+ unique_function<void ()> CapturingFunction{
339
+ [Counter = CountCopyAndMove{}] {}};
344
340
unique_function<void ()> CapturingFunctionMoved{
345
341
std::move (CapturingFunction)};
346
342
}
347
- printf ( " %i, %i \n " , NumOfMovesCalled, NumOfDestructorsCalled);
348
- EXPECT_EQ (NumOfDestructorsCalled, 1 + NumOfMovesCalled );
343
+ EXPECT_EQ ( CountCopyAndMove::TotalConstructions (),
344
+ CountCopyAndMove::Destructions );
349
345
}
350
346
351
347
} // anonymous namespace
You can’t perform that action at this time.
0 commit comments