Bug 1155500: Have nsAutoPtr transfers ownership when copying related objects. r=froydnj
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 01 May 2015 14:55:05 +1000
changeset 273334 e572ad1b9e3917e17004bcf6fe0288d29ffdef43
parent 273333 1103c98d1a93d2c0fcdfd3e2b5b8fcd8c4370565
child 273335 f227ff5d16a3d29a532b4c6555dcc39d132d6ab7
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1155500
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1155500: Have nsAutoPtr transfers ownership when copying related objects. r=froydnj This emulates auto_ptr behavior.
xpcom/base/nsAutoPtr.h
--- a/xpcom/base/nsAutoPtr.h
+++ b/xpcom/base/nsAutoPtr.h
@@ -91,22 +91,36 @@ public:
   // This constructor shouldn't exist; we should just use the &&
   // constructor.
   nsAutoPtr(nsAutoPtr<T>& aSmartPtr)
     : mRawPtr(aSmartPtr.forget())
     // Construct by transferring ownership from another smart pointer.
   {
   }
 
+  template <typename I>
+  nsAutoPtr(nsAutoPtr<I>& aSmartPtr)
+    : mRawPtr(aSmartPtr.forget())
+    // Construct by transferring ownership from another smart pointer.
+  {
+  }
+
   nsAutoPtr(nsAutoPtr<T>&& aSmartPtr)
     : mRawPtr(aSmartPtr.forget())
     // Construct by transferring ownership from another smart pointer.
   {
   }
 
+  template <typename I>
+  nsAutoPtr(nsAutoPtr<I>&& aSmartPtr)
+    : mRawPtr(aSmartPtr.forget())
+    // Construct by transferring ownership from another smart pointer.
+  {
+  }
+
   // Assignment operators
 
   nsAutoPtr<T>&
   operator=(T* aRhs)
   // assign from a raw pointer (of the right type)
   {
     assign(aRhs);
     return *this;
@@ -114,22 +128,37 @@ public:
 
   nsAutoPtr<T>& operator=(nsAutoPtr<T>& aRhs)
   // assign by transferring ownership from another smart pointer.
   {
     assign(aRhs.forget());
     return *this;
   }
 
+  template <typename I>
+  nsAutoPtr<T>& operator=(nsAutoPtr<I>& aRhs)
+  // assign by transferring ownership from another smart pointer.
+  {
+    assign(aRhs.forget());
+    return *this;
+  }
+
   nsAutoPtr<T>& operator=(nsAutoPtr<T>&& aRhs)
   {
     assign(aRhs.forget());
     return *this;
   }
 
+  template <typename I>
+  nsAutoPtr<T>& operator=(nsAutoPtr<I>&& aRhs)
+  {
+    assign(aRhs.forget());
+    return *this;
+  }
+
   // Other pointer operators
 
   T*
   get() const
   /*
     Prefer the implicit conversion provided automatically by
     |operator T*() const|.  Use |get()| _only_ to resolve
     ambiguity.