diff options
-rw-r--r-- | llvm/include/llvm/ADT/BitVector.h | 2 | ||||
-rw-r--r-- | llvm/unittests/ADT/BitVectorTest.cpp | 26 |
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h index 95a629126f2..661437126d4 100644 --- a/llvm/include/llvm/ADT/BitVector.h +++ b/llvm/include/llvm/ADT/BitVector.h @@ -105,6 +105,7 @@ public: BitVector(BitVector &&RHS) : Bits(RHS.Bits), Size(RHS.Size), Capacity(RHS.Capacity) { RHS.Bits = nullptr; + RHS.Size = RHS.Capacity = 0; } ~BitVector() { @@ -454,6 +455,7 @@ public: Capacity = RHS.Capacity; RHS.Bits = nullptr; + RHS.Size = RHS.Capacity = 0; return *this; } diff --git a/llvm/unittests/ADT/BitVectorTest.cpp b/llvm/unittests/ADT/BitVectorTest.cpp index 95ff93fa9c4..78fd5ce6567 100644 --- a/llvm/unittests/ADT/BitVectorTest.cpp +++ b/llvm/unittests/ADT/BitVectorTest.cpp @@ -399,5 +399,31 @@ TYPED_TEST(BitVectorTest, CompoundTestReset) { C.reset(C); EXPECT_TRUE(C.none()); } + +TYPED_TEST(BitVectorTest, MoveConstructor) { + TypeParam A(10, true); + TypeParam B(std::move(A)); + // Check that the move ctor leaves the moved-from object in a valid state. + // The following line used to crash. + A = B; + + TypeParam C(10, true); + EXPECT_EQ(C, A); + EXPECT_EQ(C, B); +} + +TYPED_TEST(BitVectorTest, MoveAssignment) { + TypeParam A(10, true); + TypeParam B; + B = std::move(A); + // Check that move assignment leaves the moved-from object in a valid state. + // The following line used to crash. + A = B; + + TypeParam C(10, true); + EXPECT_EQ(C, A); + EXPECT_EQ(C, B); +} + } #endif |