Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / ADT / CountCopyAndMove.h
blobc91d34bd8ebb507147b9e27c46bdc5cb2af4a290
1 //===- llvm/unittest/ADT/CountCopyAndMove.h - Optional unit tests ---------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H
10 #define LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H
12 namespace llvm {
14 struct CountCopyAndMove {
15 static int DefaultConstructions;
16 static int ValueConstructions;
17 static int CopyConstructions;
18 static int CopyAssignments;
19 static int MoveConstructions;
20 static int MoveAssignments;
21 static int Destructions;
22 int val;
24 CountCopyAndMove() { ++DefaultConstructions; }
25 explicit CountCopyAndMove(int val) : val(val) { ++ValueConstructions; }
26 CountCopyAndMove(const CountCopyAndMove &other) : val(other.val) {
27 ++CopyConstructions;
29 CountCopyAndMove &operator=(const CountCopyAndMove &other) {
30 val = other.val;
31 ++CopyAssignments;
32 return *this;
34 CountCopyAndMove(CountCopyAndMove &&other) : val(other.val) {
35 ++MoveConstructions;
37 CountCopyAndMove &operator=(CountCopyAndMove &&other) {
38 val = other.val;
39 ++MoveAssignments;
40 return *this;
42 ~CountCopyAndMove() { ++Destructions; }
44 static void ResetCounts() {
45 DefaultConstructions = 0;
46 ValueConstructions = 0;
47 CopyConstructions = 0;
48 CopyAssignments = 0;
49 MoveConstructions = 0;
50 MoveAssignments = 0;
51 Destructions = 0;
54 static int TotalConstructions() {
55 return DefaultConstructions + ValueConstructions + MoveConstructions +
56 CopyConstructions;
59 static int TotalCopies() { return CopyConstructions + CopyAssignments; }
61 static int TotalMoves() { return MoveConstructions + MoveAssignments; }
64 } // end namespace llvm
66 #endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H