]> granicus.if.org Git - llvm/commitdiff
Fix BitVector move ctor/assignment.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 16 Jun 2016 21:45:13 +0000 (21:45 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 16 Jun 2016 21:45:13 +0000 (21:45 +0000)
Current implementation leaves the object in an invalid state.

This reverts commit bf0c389ac683cd6c0e5959b16537e59e5f4589e3.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272965 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/BitVector.h
unittests/ADT/BitVectorTest.cpp

index 95a629126f2cc90c1f257b8dd74428b459461bd3..661437126d4885af5f0f7930ac9f11e98f42528a 100644 (file)
@@ -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;
   }
index 95ff93fa9c4c8a35957f57b2115678169b52394e..78fd5ce65677cd6c941b401b09787b3fb2e5835a 100644 (file)
@@ -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