Bug 1469155 - Add overloading for std::nullptr_t for RangedPtr equality operator r=froydnj
authorviolet <violet.bugreport@gmail.com>
Tue, 26 Mar 2019 19:10:24 +0000
changeset 466256 7048099916185816c362663855ae3a79cb183e6d
parent 466255 334d8f9c99957c9eef94ecf99437a0b8e7dda7c7
child 466257 9eaf669d5fec6b897bbce1a76899bd426130e778
push id35762
push usercsabou@mozilla.com
push dateWed, 27 Mar 2019 04:44:00 +0000
treeherdermozilla-central@bc572aee49b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1469155
milestone68.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 1469155 - Add overloading for std::nullptr_t for RangedPtr equality operator r=froydnj Templated pointer can't match |nullptr|, we should add overloading for std::nullptr_t specifically to be able to support |nullptr|. Differential Revision: https://phabricator.services.mozilla.com/D24925
mfbt/RangedPtr.h
mfbt/tests/TestRange.cpp
--- a/mfbt/RangedPtr.h
+++ b/mfbt/RangedPtr.h
@@ -12,16 +12,17 @@
 #ifndef mozilla_RangedPtr_h
 #define mozilla_RangedPtr_h
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 
 #include <stdint.h>
+#include <cstddef>
 
 namespace mozilla {
 
 /*
  * RangedPtr is a smart pointer restricted to an address range specified at
  * creation.  The pointer (and any smart pointers derived from it) must remain
  * within the range [start, end] (inclusive of end to facilitate use as
  * sentinels).  Dereferencing or indexing into the pointer (or pointers derived
@@ -241,16 +242,19 @@ class RangedPtr {
   bool operator==(const U* u) const {
     return mPtr == u;
   }
   template <typename U>
   bool operator!=(const U* u) const {
     return !(*this == u);
   }
 
+  bool operator==(std::nullptr_t) const { return mPtr == nullptr; }
+  bool operator!=(std::nullptr_t) const { return mPtr != nullptr; }
+
   template <typename U>
   bool operator<(const RangedPtr<U>& aOther) const {
     return mPtr < aOther.mPtr;
   }
   template <typename U>
   bool operator<=(const RangedPtr<U>& aOther) const {
     return mPtr <= aOther.mPtr;
   }
--- a/mfbt/tests/TestRange.cpp
+++ b/mfbt/tests/TestRange.cpp
@@ -10,10 +10,15 @@
 using mozilla::IsConvertible;
 using mozilla::Range;
 
 static_assert(IsConvertible<Range<int>, Range<const int>>::value,
               "Range should convert into const");
 static_assert(!IsConvertible<Range<const int>, Range<int>>::value,
               "Range should not drop const in conversion");
 
+void test_RangeToBoolConversionShouldCompile() {
+  auto dummy = bool{Range<int>{}};
+  (void)dummy;
+}
+
 // We need a proper program so we have someplace to hang the static_asserts.
 int main() { return 0; }