explicit operator bool for CFX_RetainPtr and CFX_CountRef
Review-Url: https://codereview.chromium.org/2324733003
diff --git a/core/fxcrt/cfx_retain_ptr_unittest.cpp b/core/fxcrt/cfx_retain_ptr_unittest.cpp
index 4e74e52..9da0d5c 100644
--- a/core/fxcrt/cfx_retain_ptr_unittest.cpp
+++ b/core/fxcrt/cfx_retain_ptr_unittest.cpp
@@ -208,8 +208,8 @@
PseudoRetainable obj1;
CFX_RetainPtr<PseudoRetainable> null_ptr;
CFX_RetainPtr<PseudoRetainable> obj1_ptr(&obj1);
- bool null_bool = null_ptr;
- bool obj1_bool = obj1_ptr;
+ bool null_bool = !!null_ptr;
+ bool obj1_bool = !!obj1_ptr;
EXPECT_FALSE(null_bool);
EXPECT_TRUE(obj1_bool);
}
diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h
index 95132a7..d709efb 100644
--- a/core/fxcrt/include/cfx_count_ref.h
+++ b/core/fxcrt/include/cfx_count_ref.h
@@ -47,7 +47,7 @@
return m_pObject == that.m_pObject;
}
bool operator!=(const CFX_CountRef& that) const { return !(*this == that); }
- operator bool() const { return m_pObject; }
+ explicit operator bool() const { return !!m_pObject; }
private:
class CountedObj : public ObjClass {
diff --git a/core/fxcrt/include/cfx_retain_ptr.h b/core/fxcrt/include/cfx_retain_ptr.h
index 25edd58..e40feb6 100644
--- a/core/fxcrt/include/cfx_retain_ptr.h
+++ b/core/fxcrt/include/cfx_retain_ptr.h
@@ -46,7 +46,7 @@
bool operator!=(const CFX_RetainPtr& that) const { return !(*this == that); }
- operator bool() const { return !!m_pObj; }
+ explicit operator bool() const { return !!m_pObj; }
T& operator*() const { return *m_pObj.get(); }
T* operator->() const { return m_pObj.get(); }