[libcxx] r215301 - Add some extra checks to the MoveOnly test class to ensure it is not constructed or assigned from in a moved-from state.

David Blaikie dblaikie at gmail.com
Sat Aug 9 15:35:47 PDT 2014


Author: dblaikie
Date: Sat Aug  9 17:35:47 2014
New Revision: 215301

URL: http://llvm.org/viewvc/llvm-project?rev=215301&view=rev
Log:
Add some extra checks to the MoveOnly test class to ensure it is not constructed or assigned from in a moved-from state.

Some tests were constructing it with 0, so use -1 as the invalid state
instead.

Reviewers: Marshall Clow

Differential Revision: http://reviews.llvm.org/D4095

Modified:
    libcxx/trunk/test/containers/MoveOnly.h

Modified: libcxx/trunk/test/containers/MoveOnly.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/MoveOnly.h?rev=215301&r1=215300&r2=215301&view=diff
==============================================================================
--- libcxx/trunk/test/containers/MoveOnly.h (original)
+++ libcxx/trunk/test/containers/MoveOnly.h Sat Aug  9 17:35:47 2014
@@ -22,11 +22,17 @@ class MoveOnly
 
     int data_;
 public:
-    MoveOnly(int data = 1) : data_(data) {}
-    MoveOnly(MoveOnly&& x)
-        : data_(x.data_) {x.data_ = 0;}
-    MoveOnly& operator=(MoveOnly&& x)
-        {data_ = x.data_; x.data_ = 0; return *this;}
+    MoveOnly(int data = 0) : data_(data) { assert(data != -1); }
+    MoveOnly(MoveOnly &&x) : data_(x.data_) {
+        assert(x.data_ != -1);
+        x.data_ = -1;
+    }
+    MoveOnly &operator=(MoveOnly &&x) {
+        assert(x.data_ != -1);
+        data_ = x.data_;
+        x.data_ = -1;
+        return *this;
+    }
 
     int get() const {return data_;}
 





More information about the cfe-commits mailing list