Bug 1316432 - nsCOMPtr construction/assignment from nullptr - r=froydnj
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 11 Nov 2016 07:57:38 +1100
changeset 321997 376b38e78518ba0774db44085ec9586bd5ddbdbf
parent 321996 09a8134e26ea7b22e6b3c316d2089f4a0ffe5456
child 321998 8d3dcf1db881af59d7cff15d3964d14f9c075812
push id34128
push usergsquelart@mozilla.com
push dateThu, 10 Nov 2016 22:05:23 +0000
treeherderautoland@8d3dcf1db881 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1316432
milestone52.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 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()|.