From 6f7cb576891834f1dcd87e66a32e869b82602151 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 20 Aug 2015 10:30:10 +1000 Subject: [PATCH] Bug 1196050 - Replace NSCAP_Zero usage with decltype(nullptr). r=froydnj --- parser/html/nsHtml5RefPtr.h | 20 +++++++---------- xpcom/base/nsAutoPtr.h | 44 +++++++++++++++---------------------- xpcom/glue/nsCOMPtr.h | 24 ++++++++------------ 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/parser/html/nsHtml5RefPtr.h b/parser/html/nsHtml5RefPtr.h index 17fffae9cb5..89e56924811 100644 --- a/parser/html/nsHtml5RefPtr.h +++ b/parser/html/nsHtml5RefPtr.h @@ -417,37 +417,33 @@ operator!=( U* lhs, const nsHtml5RefPtr& rhs ) template inline bool -operator==( const nsHtml5RefPtr& lhs, NSCAP_Zero* rhs ) - // specifically to allow |smartPtr == 0| +operator==( const nsHtml5RefPtr& lhs, decltype(nullptr) ) { - return static_cast(lhs.get()) == reinterpret_cast(rhs); + return lhs.get() == nullptr; } template inline bool -operator==( NSCAP_Zero* lhs, const nsHtml5RefPtr& rhs ) - // specifically to allow |0 == smartPtr| +operator==( decltype(nullptr), const nsHtml5RefPtr& rhs ) { - return reinterpret_cast(lhs) == static_cast(rhs.get()); + return nullptr == rhs.get(); } template inline bool -operator!=( const nsHtml5RefPtr& lhs, NSCAP_Zero* rhs ) - // specifically to allow |smartPtr != 0| +operator!=( const nsHtml5RefPtr& lhs, decltype(nullptr) ) { - return static_cast(lhs.get()) != reinterpret_cast(rhs); + return lhs.get() != nullptr; } template inline bool -operator!=( NSCAP_Zero* lhs, const nsHtml5RefPtr& rhs ) - // specifically to allow |0 != smartPtr| +operator!=( decltype(nullptr), const nsHtml5RefPtr& rhs ) { - return reinterpret_cast(lhs) != static_cast(rhs.get()); + return nullptr != rhs.get(); } #endif // !defined(nsHtml5RefPtr_h) diff --git a/xpcom/base/nsAutoPtr.h b/xpcom/base/nsAutoPtr.h index c2f53314a32..eaaaf90e175 100644 --- a/xpcom/base/nsAutoPtr.h +++ b/xpcom/base/nsAutoPtr.h @@ -414,38 +414,34 @@ operator!=(U* aLhs, const nsAutoPtr& aRhs) -// Comparing an |nsAutoPtr| to |0| +// Comparing an |nsAutoPtr| to |nullptr| template inline bool -operator==(const nsAutoPtr& aLhs, NSCAP_Zero* aRhs) -// specifically to allow |smartPtr == 0| +operator==(const nsAutoPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) == reinterpret_cast(aRhs); + return aLhs.get() == nullptr; } template inline bool -operator==(NSCAP_Zero* aLhs, const nsAutoPtr& aRhs) -// specifically to allow |0 == smartPtr| +operator==(decltype(nullptr), const nsAutoPtr& aRhs) { - return reinterpret_cast(aLhs) == static_cast(aRhs.get()); + return nullptr == aRhs.get(); } template inline bool -operator!=(const nsAutoPtr& aLhs, NSCAP_Zero* aRhs) -// specifically to allow |smartPtr != 0| +operator!=(const nsAutoPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) != reinterpret_cast(aRhs); + return aLhs.get() != nullptr; } template inline bool -operator!=(NSCAP_Zero* aLhs, const nsAutoPtr& aRhs) -// specifically to allow |0 != smartPtr| +operator!=(decltype(nullptr), const nsAutoPtr& aRhs) { - return reinterpret_cast(aLhs) != static_cast(aRhs.get()); + return nullptr != aRhs.get(); } @@ -766,38 +762,34 @@ operator!=(U* aLhs, const nsAutoArrayPtr& aRhs) -// Comparing an |nsAutoArrayPtr| to |0| +// Comparing an |nsAutoArrayPtr| to |nullptr| template inline bool -operator==(const nsAutoArrayPtr& aLhs, NSCAP_Zero* aRhs) -// specifically to allow |smartPtr == 0| +operator==(const nsAutoArrayPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) == reinterpret_cast(aRhs); + return aLhs.get() == nullptr; } template inline bool -operator==(NSCAP_Zero* aLhs, const nsAutoArrayPtr& aRhs) -// specifically to allow |0 == smartPtr| +operator==(decltype(nullptr), const nsAutoArrayPtr& aRhs) { - return reinterpret_cast(aLhs) == static_cast(aRhs.get()); + return nullptr == aRhs.get(); } template inline bool -operator!=(const nsAutoArrayPtr& aLhs, NSCAP_Zero* aRhs) -// specifically to allow |smartPtr != 0| +operator!=(const nsAutoArrayPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) != reinterpret_cast(aRhs); + return aLhs.get() != nullptr; } template inline bool -operator!=(NSCAP_Zero* aLhs, const nsAutoArrayPtr& aRhs) -// specifically to allow |0 != smartPtr| +operator!=(decltype(nullptr), const nsAutoArrayPtr& aRhs) { - return reinterpret_cast(aLhs) != static_cast(aRhs.get()); + return nullptr != aRhs.get(); } diff --git a/xpcom/glue/nsCOMPtr.h b/xpcom/glue/nsCOMPtr.h index 4758021b2f5..406e7836cda 100644 --- a/xpcom/glue/nsCOMPtr.h +++ b/xpcom/glue/nsCOMPtr.h @@ -1350,40 +1350,34 @@ operator!=(U* aLhs, const nsCOMPtr& aRhs) -// Comparing an |nsCOMPtr| to |0| +// Comparing an |nsCOMPtr| to |nullptr| -class NSCAP_Zero; - -// Specifically to allow |smartPtr == 0|. template inline bool -operator==(const nsCOMPtr& aLhs, NSCAP_Zero* aRhs) +operator==(const nsCOMPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) == reinterpret_cast(aRhs); + return aLhs.get() == nullptr; } -// Specifically to allow |0 == smartPtr|. template inline bool -operator==(NSCAP_Zero* aLhs, const nsCOMPtr& aRhs) +operator==(decltype(nullptr), const nsCOMPtr& aRhs) { - return reinterpret_cast(aLhs) == static_cast(aRhs.get()); + return nullptr == aRhs.get(); } -// Specifically to allow |smartPtr != 0|. template inline bool -operator!=(const nsCOMPtr& aLhs, NSCAP_Zero* aRhs) +operator!=(const nsCOMPtr& aLhs, decltype(nullptr)) { - return static_cast(aLhs.get()) != reinterpret_cast(aRhs); + return aLhs.get() != nullptr; } -// Specifically to allow |0 != smartPtr|. template inline bool -operator!=(NSCAP_Zero* aLhs, const nsCOMPtr& aRhs) +operator!=(decltype(nullptr), const nsCOMPtr& aRhs) { - return reinterpret_cast(aLhs) != static_cast(aRhs.get()); + return nullptr != aRhs.get(); }