Bug 1116905 - part 4 - remove implicit conversion from non-nullptr T* to TemporaryRef<T>; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Thu, 30 Apr 2015 15:21:05 -0400
changeset 277472 b1c86100dbce2eef1686b57b59c76ff78cfbc376
parent 277471 f1f569c211024cf1855f5fbedb17e8648a915ae5
child 277473 e9b68252df54c12015382d022f01e06c5605e27a
push id897
push userjlund@mozilla.com
push dateMon, 14 Sep 2015 18:56:12 +0000
treeherdermozilla-release@9411e2d2b214 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1116905
milestone41.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 1116905 - part 4 - remove implicit conversion from non-nullptr T* to TemporaryRef<T>; r=ehsan
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -8,16 +8,17 @@
 
 #ifndef mozilla_RefPtr_h
 #define mozilla_RefPtr_h
 
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Move.h"
 #include "mozilla/RefCountType.h"
 #include "mozilla/TypeTraits.h"
 #if defined(MOZILLA_INTERNAL_API)
 #include "nsXPCOM.h"
 #endif
 
 #if defined(MOZILLA_INTERNAL_API) && \
     !defined(MOZILLA_XPCOMRT_API) && \
@@ -322,17 +323,23 @@ template<typename T>
 class TemporaryRef
 {
   // To allow it to construct TemporaryRef from a bare T*
   friend class RefPtr<T>;
 
   typedef typename RefPtr<T>::DontRef DontRef;
 
 public:
-  MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr<T>::ref(aVal)) {}
+  // Please see already_AddRefed for a description of what these constructors
+  // do.
+  TemporaryRef() : mPtr(nullptr) {}
+  typedef void (TemporaryRef::* MatchNullptr)(double, float);
+  MOZ_IMPLICIT TemporaryRef(MatchNullptr aRawPtr) : mPtr(nullptr) {}
+  explicit TemporaryRef(T* aVal) : mPtr(RefPtr<T>::ref(aVal)) {}
+
   TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.take()) {}
 
   template<typename U>
   TemporaryRef(const TemporaryRef<U>& aOther) : mPtr(aOther.take()) {}
 
   ~TemporaryRef() { RefPtr<T>::unref(mPtr); }
 
   MOZ_WARN_UNUSED_RESULT T* take() const
@@ -342,17 +349,16 @@ public:
     return tmp;
   }
 
 private:
   TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {}
 
   mutable T* MOZ_OWNING_REF mPtr;
 
-  TemporaryRef() = delete;
   void operator=(const TemporaryRef&) = delete;
 };
 
 /**
  * OutParamRef is a wrapper that tracks a refcounted pointer passed as
  * an outparam argument to a function.  OutParamRef implements COM T**
  * outparam semantics: this requires the callee to AddRef() the T*
  * returned through the T** outparam on behalf of the caller.  This