[llvm] r202949 - [C++11] Add release() to OwningPtr.

Ahmed Charles ahmedcharles at gmail.com
Wed Mar 5 00:25:08 PST 2014


Author: ace2001ac
Date: Wed Mar  5 02:25:08 2014
New Revision: 202949

URL: http://llvm.org/viewvc/llvm-project?rev=202949&view=rev
Log:
[C++11] Add release() to OwningPtr.

This will make the transition to unique_ptr easier by allowing more
incremental changes.

Modified:
    llvm/trunk/include/llvm/ADT/OwningPtr.h
    llvm/trunk/unittests/ADT/OwningPtrTest.cpp

Modified: llvm/trunk/include/llvm/ADT/OwningPtr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/OwningPtr.h?rev=202949&r1=202948&r2=202949&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/OwningPtr.h (original)
+++ llvm/trunk/include/llvm/ADT/OwningPtr.h Wed Mar  5 02:25:08 2014
@@ -73,6 +73,8 @@ public:
     return Tmp;
   }
 
+  T *release() { return take(); }
+
   std::unique_ptr<T> take_unique() { return std::unique_ptr<T>(take()); }
 
   T &operator*() const {

Modified: llvm/trunk/unittests/ADT/OwningPtrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/OwningPtrTest.cpp?rev=202949&r1=202948&r2=202949&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/OwningPtrTest.cpp (original)
+++ llvm/trunk/unittests/ADT/OwningPtrTest.cpp Wed Mar  5 02:25:08 2014
@@ -90,6 +90,24 @@ TEST_F(OwningPtrTest, Take) {
   EXPECT_EQ(1u, TrackDestructor::Destructions);
 }
 
+TEST_F(OwningPtrTest, Release) {
+  TrackDestructor::ResetCounts();
+  TrackDestructor *T = 0;
+  {
+    OwningPtr<TrackDestructor> O(new TrackDestructor(3));
+    T = O.release();
+    EXPECT_FALSE((bool)O);
+    EXPECT_TRUE(!O);
+    EXPECT_FALSE(O.get());
+    EXPECT_FALSE(O.isValid());
+    EXPECT_TRUE(T);
+    EXPECT_EQ(3, T->val);
+    EXPECT_EQ(0u, TrackDestructor::Destructions);
+  }
+  delete T;
+  EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
 TEST_F(OwningPtrTest, MoveConstruction) {
   TrackDestructor::ResetCounts();
   {





More information about the llvm-commits mailing list