| Index: base/memory/ref_counted.h
|
| diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
|
| index 7869e72d11126cdc1492840b14c68b3a393de54a..219437ed8d82b8b35835a6c3297d5f719f14c277 100644
|
| --- a/base/memory/ref_counted.h
|
| +++ b/base/memory/ref_counted.h
|
| @@ -17,10 +17,6 @@
|
| #include "base/threading/thread_collision_warner.h"
|
| #include "build/build_config.h"
|
|
|
| -#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_ANDROID)
|
| -#define DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR
|
| -#endif
|
| -
|
| namespace base {
|
|
|
| namespace subtle {
|
| @@ -297,12 +293,6 @@ class scoped_refptr {
|
|
|
| T* get() const { return ptr_; }
|
|
|
| -#if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
|
| - // Allow scoped_refptr<C> to be used in boolean expression
|
| - // and comparison operations.
|
| - operator T*() const { return ptr_; }
|
| -#endif
|
| -
|
| T& operator*() const {
|
| assert(ptr_ != NULL);
|
| return *ptr_;
|
| @@ -343,7 +333,19 @@ class scoped_refptr {
|
| swap(&r.ptr_);
|
| }
|
|
|
| -#if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
|
| + private:
|
| + // Allow scoped_refptr<T> to be used in boolean expressions, but not
|
| + // implicitly convertible to a real bool (which is dangerous).
|
| + //
|
| + // Note that this trick is only safe when the == and != operators
|
| + // are declared explicitly, as otherwise "refptr1 == refptr2"
|
| + // will compile but do the wrong thing (i.e., convert to Testable
|
| + // and then do the comparison).
|
| + typedef T* scoped_refptr::*Testable;
|
| +
|
| + public:
|
| + operator Testable() const { return ptr_ ? &scoped_refptr::ptr_ : nullptr; }
|
| +
|
| template <typename U>
|
| bool operator==(const scoped_refptr<U>& rhs) const {
|
| return ptr_ == rhs.get();
|
| @@ -358,7 +360,6 @@ class scoped_refptr {
|
| bool operator<(const scoped_refptr<U>& rhs) const {
|
| return ptr_ < rhs.get();
|
| }
|
| -#endif
|
|
|
| protected:
|
| T* ptr_;
|
| @@ -389,8 +390,8 @@ scoped_refptr<T> make_scoped_refptr(T* t) {
|
| return scoped_refptr<T>(t);
|
| }
|
|
|
| -#if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
|
| -// Temporary operator overloads to facilitate the transition...
|
| +// Temporary operator overloads to facilitate the transition. See
|
| +// https://crbug.com/110610.
|
| template <typename T, typename U>
|
| bool operator==(const scoped_refptr<T>& lhs, const U* rhs) {
|
| return lhs.get() == rhs;
|
| @@ -415,6 +416,5 @@ template <typename T>
|
| std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) {
|
| return out << p.get();
|
| }
|
| -#endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
|
|
|
| #endif // BASE_MEMORY_REF_COUNTED_H_
|
|
|