Bug 1193762 part 9 - Delete nsCOMPtr<T>::operator T*()&&; r=froydnj
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 21:29:23 +0300
changeset 295685 a0daadf6943ce11e9858cdcb7aacfd63dfc0ce39
parent 295684 c01fbb04e9a885c35ba47532e17e0eab9d73fdc7
child 295686 3b968080b282bfe3ccbcf0c52c65a7da90fd85a3
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1193762
milestone49.0a1
Bug 1193762 part 9 - Delete nsCOMPtr<T>::operator T*()&&; r=froydnj
xpcom/glue/nsCOMPtr.h
--- a/xpcom/glue/nsCOMPtr.h
+++ b/xpcom/glue/nsCOMPtr.h
@@ -721,17 +721,31 @@ public:
   T* get() const { return reinterpret_cast<T*>(mRawPtr); }
 
   // Makes an nsCOMPtr act like its underlying raw pointer type whenever it is
   // used in a context where a raw pointer is expected. It is this operator
   // that makes an nsCOMPtr substitutable for a raw pointer.
   //
   // Prefer the implicit use of this operator to calling |get()|, except where
   // necessary to resolve ambiguity.
-  operator T*() const { return get(); }
+  operator T*() const
+#ifdef MOZ_HAVE_REF_QUALIFIERS
+  &
+#endif
+  { return get(); }
+
+#ifdef MOZ_HAVE_REF_QUALIFIERS
+  // Don't allow implicit conversion of temporary nsCOMPtr to raw pointer,
+  // because the refcount might be one and the pointer will immediately become
+  // invalid.
+  operator T*() const && = delete;
+
+  // Needed to avoid the deleted operator above
+  explicit operator bool() const { return !!mRawPtr; }
+#endif
 
   T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN
   {
     MOZ_ASSERT(mRawPtr != 0,
                "You can't dereference a NULL nsCOMPtr with operator->().");
     return get();
   }