[llvm] ee4c811 - [ADT] Move MoveOnly to a header file (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 00:31:53 PST 2022
Author: Kazu Hirata
Date: 2022-12-11T00:31:46-08:00
New Revision: ee4c8119a6d3c42d767f2bf1c9ea230d805b382d
URL: https://github.com/llvm/llvm-project/commit/ee4c8119a6d3c42d767f2bf1c9ea230d805b382d
DIFF: https://github.com/llvm/llvm-project/commit/ee4c8119a6d3c42d767f2bf1c9ea230d805b382d.diff
LOG: [ADT] Move MoveOnly to a header file (NFC)
This patch moves MoveOnly to a header file so that I can use it from
another .cpp file.
Differential Revision: https://reviews.llvm.org/D139781
Added:
llvm/unittests/ADT/MoveOnly.cpp
llvm/unittests/ADT/MoveOnly.h
Modified:
llvm/unittests/ADT/CMakeLists.txt
llvm/unittests/ADT/OptionalTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/ADT/CMakeLists.txt b/llvm/unittests/ADT/CMakeLists.txt
index b3b375ef7091f..8cddaa50341f8 100644
--- a/llvm/unittests/ADT/CMakeLists.txt
+++ b/llvm/unittests/ADT/CMakeLists.txt
@@ -48,6 +48,7 @@ add_llvm_unittest(ADTTests
IteratorTest.cpp
MappedIteratorTest.cpp
MapVectorTest.cpp
+ MoveOnly.cpp
OptionalTest.cpp
PackedVectorTest.cpp
PointerEmbeddedIntTest.cpp
diff --git a/llvm/unittests/ADT/MoveOnly.cpp b/llvm/unittests/ADT/MoveOnly.cpp
new file mode 100644
index 0000000000000..541903bbe9467
--- /dev/null
+++ b/llvm/unittests/ADT/MoveOnly.cpp
@@ -0,0 +1,15 @@
+//===- llvm/unittest/ADT/MoveOnly.cpp - Optional unit tests ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MoveOnly.h"
+
+using namespace llvm;
+
+unsigned MoveOnly::MoveConstructions = 0;
+unsigned MoveOnly::Destructions = 0;
+unsigned MoveOnly::MoveAssignments = 0;
diff --git a/llvm/unittests/ADT/MoveOnly.h b/llvm/unittests/ADT/MoveOnly.h
new file mode 100644
index 0000000000000..ad64deae771ba
--- /dev/null
+++ b/llvm/unittests/ADT/MoveOnly.h
@@ -0,0 +1,42 @@
+//===- llvm/unittest/ADT/MoveOnly.h - Optional unit tests -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_UNITTESTS_ADT_MOVEONLY_H
+#define LLVM_UNITTESTS_ADT_MOVEONLY_H
+
+namespace llvm {
+
+struct MoveOnly {
+ static unsigned MoveConstructions;
+ static unsigned Destructions;
+ static unsigned MoveAssignments;
+ int val;
+ explicit MoveOnly(int val) : val(val) {
+ }
+ MoveOnly(MoveOnly&& other) {
+ val = other.val;
+ ++MoveConstructions;
+ }
+ MoveOnly &operator=(MoveOnly&& other) {
+ val = other.val;
+ ++MoveAssignments;
+ return *this;
+ }
+ ~MoveOnly() {
+ ++Destructions;
+ }
+ static void ResetCounts() {
+ MoveConstructions = 0;
+ Destructions = 0;
+ MoveAssignments = 0;
+ }
+};
+
+} // end namespace llvm
+
+#endif // LLVM_UNITTESTS_ADT_MOVEONLY_H
diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp
index a98d230fd346b..b192d5321b28b 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -10,6 +10,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/raw_ostream.h"
+#include "MoveOnly.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
@@ -292,36 +293,6 @@ TEST(OptionalTest, InPlaceConstructionAndEmplaceEquivalentTest) {
EXPECT_EQ(2u, MultiArgConstructor::Destructions);
}
-struct MoveOnly {
- static unsigned MoveConstructions;
- static unsigned Destructions;
- static unsigned MoveAssignments;
- int val;
- explicit MoveOnly(int val) : val(val) {
- }
- MoveOnly(MoveOnly&& other) {
- val = other.val;
- ++MoveConstructions;
- }
- MoveOnly &operator=(MoveOnly&& other) {
- val = other.val;
- ++MoveAssignments;
- return *this;
- }
- ~MoveOnly() {
- ++Destructions;
- }
- static void ResetCounts() {
- MoveConstructions = 0;
- Destructions = 0;
- MoveAssignments = 0;
- }
-};
-
-unsigned MoveOnly::MoveConstructions = 0;
-unsigned MoveOnly::Destructions = 0;
-unsigned MoveOnly::MoveAssignments = 0;
-
static_assert(!std::is_trivially_copyable_v<Optional<MoveOnly>>,
"not trivially copyable");
More information about the llvm-commits
mailing list