[PATCH] D21423: Fix BitVector move ctor/assignment.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 14:08:24 PDT 2016


eugenis updated this revision to Diff 61027.

Repository:
  rL LLVM

http://reviews.llvm.org/D21423

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

Index: unittests/ADT/BitVectorTest.cpp
===================================================================
--- unittests/ADT/BitVectorTest.cpp
+++ unittests/ADT/BitVectorTest.cpp
@@ -399,5 +399,31 @@
   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
Index: include/llvm/ADT/BitVector.h
===================================================================
--- include/llvm/ADT/BitVector.h
+++ include/llvm/ADT/BitVector.h
@@ -105,6 +105,7 @@
   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 @@
     Capacity = RHS.Capacity;
 
     RHS.Bits = nullptr;
+    RHS.Size = RHS.Capacity = 0;
 
     return *this;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21423.61027.patch
Type: text/x-patch
Size: 1376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160616/27d535dd/attachment.bin>


More information about the llvm-commits mailing list