We need this for RangedPtr<T> to be drop-in replacements for T* on some algorithms. You can only subtract two RangedPtr<T>s if they have identical ranges.
Hi Nathan, Does the overloading function  did what this bug wants to do (did not check if they have identical ranges)? BTW, why do we need to check the MOZ_ASSERT(mPtr >= aOther.mPtr); and only return the positive length? I guess the answer is we cannot use ptrdiff_t? Thank you!  https://dxr.mozilla.org/mozilla-central/rev/f0f15b7c6aa77a0c5750918aa0a1cb3dc82185bc/mfbt/RangedPtr.h#279  http://en.cppreference.com/w/cpp/types/ptrdiff_t
(In reply to James Cheng[:JamesCheng] from comment #1) > Does the overloading function  did what this bug wants to do (did not > check if they have identical ranges)? I somehow missed this method when reading through the RangedPtr implementation! This method does do what I want, at the cost of disallowing subtraction of arbitrary pointers. I don't know if that's necessarily a problem, though. > BTW, why do we need to check the MOZ_ASSERT(mPtr >= aOther.mPtr); and only > return the positive length? > I guess the answer is we cannot use ptrdiff_t? I think the comment before PointerRangeSize explains why we need the check here: http://dxr.mozilla.org/mozilla-central/source/mfbt/ArrayUtils.h#29 We could use ptrdiff_t, but that would not be a fully general solution. I'm unsure if the handwavings about compiler bugs still exist nowadays, too.