Bug 1316432 - nsCOMPtr construction/assignment from nullptr - r=froydnj draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 11 Nov 2016 07:57:38 +1100
changeset 437457 de8fc2f900abbf7f0bf763ffac8f23f9cde298b4
parent 437456 a5a9a064335254a7456a7ec48805c4ec08fd18af
child 437458 f9dcc6b06e9ebf9c30a576f9319f76a51b6dc26f
push id35411
push usergsquelart@mozilla.com
push dateThu, 10 Nov 2016 22:02:18 +0000
reviewersfroydnj
bugs1316432
milestone52.0a1
Bug 1316432 - nsCOMPtr construction/assignment from nullptr - r=froydnj MozReview-Commit-ID: 4KW3g2WSJaC
xpcom/glue/nsCOMPtr.h
--- a/xpcom/glue/nsCOMPtr.h
+++ b/xpcom/glue/nsCOMPtr.h
@@ -425,16 +425,23 @@ public:
 
   nsCOMPtr()
     : NSCAP_CTOR_BASE(nullptr)
   {
     assert_validity();
     NSCAP_LOG_ASSIGNMENT(this, nullptr);
   }
 
+  MOZ_IMPLICIT nsCOMPtr(decltype(nullptr))
+    : NSCAP_CTOR_BASE(nullptr)
+  {
+    assert_validity();
+    NSCAP_LOG_ASSIGNMENT(this, nullptr);
+  }
+
   nsCOMPtr(const nsCOMPtr<T>& aSmartPtr)
     : NSCAP_CTOR_BASE(aSmartPtr.mRawPtr)
   {
     assert_validity();
     if (mRawPtr) {
       NSCAP_ADDREF(this, mRawPtr);
     }
     NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
@@ -583,16 +590,22 @@ public:
 
   nsCOMPtr<T>& operator=(T* aRhs)
   {
     assign_with_AddRef(aRhs);
     NSCAP_ASSERT_NO_QUERY_NEEDED();
     return *this;
   }
 
+  nsCOMPtr<T>& operator=(decltype(nullptr))
+  {
+    assign_assuming_AddRef(nullptr);
+    return *this;
+  }
+
   // Assign from |already_AddRefed|.
   template<typename U>
   nsCOMPtr<T>& operator=(already_AddRefed<U>& aRhs)
   {
     // Make sure that U actually inherits from T
     static_assert(mozilla::IsBaseOf<T, U>::value,
                   "U is not a subclass of T");
     assign_assuming_AddRef(static_cast<T*>(aRhs.take()));
@@ -800,16 +813,22 @@ public:
   // Constructors
 
   nsCOMPtr()
     : nsCOMPtr_base(nullptr)
   {
     NSCAP_LOG_ASSIGNMENT(this, nullptr);
   }
 
+  MOZ_IMPLICIT nsCOMPtr(decltype(nullptr))
+    : nsCOMPtr_base(nullptr)
+  {
+    NSCAP_LOG_ASSIGNMENT(this, nullptr);
+  }
+
   nsCOMPtr(const nsCOMPtr<nsISupports>& aSmartPtr)
     : nsCOMPtr_base(aSmartPtr.mRawPtr)
   {
     if (mRawPtr) {
       NSCAP_ADDREF(this, mRawPtr);
     }
     NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
   }
@@ -904,16 +923,22 @@ public:
   }
 
   nsCOMPtr<nsISupports>& operator=(nsISupports* aRhs)
   {
     assign_with_AddRef(aRhs);
     return *this;
   }
 
+  nsCOMPtr<nsISupports>& operator=(decltype(nullptr))
+  {
+    assign_assuming_AddRef(nullptr);
+    return *this;
+  }
+
   // Assign from |already_AddRefed|.
   nsCOMPtr<nsISupports>& operator=(already_AddRefed<nsISupports>& aRhs)
   {
     assign_assuming_AddRef(aRhs.take());
     return *this;
   }
 
   // Assign from |otherComPtr.forget()|.