Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1899)

Unified Diff: base/memory/ref_counted.h

Issue 1958823002: Fix implicit access to raw pointer of scoped_refptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/threading/thread_unittest.cc » ('j') | chrome/browser/themes/theme_service.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ref_counted.h
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
index 0c0e0afd770f4bb3f71d222b098d200c4e3688d4..100668ff1c6bb02ba7363c6e6e9c78ef0828de23 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -362,31 +362,12 @@ class scoped_refptr {
swap(&r.ptr_);
}
+ explicit operator bool() const { return ptr_ != nullptr; }
+
private:
danakj 2016/05/10 21:37:46 There's no reason to make a private block for this
danakj 2016/05/10 21:38:51 (I'm also wondering why it's here, we're calling .
scheib 2016/05/10 22:25:00 Done, moved friend to bottom private section and c
template <typename U> friend class scoped_refptr;
- // Implement "Safe Bool Idiom"
- // https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool
- //
- // Allow scoped_refptr<T> to be used in boolean expressions such as
- // if (ref_ptr_instance)
- // But do not become convertible to a real bool (which is dangerous).
- // Implementation requires:
- // typedef Testable
- // operator Testable() const
- // operator==
- // operator!=
- //
- // == and != operators must be declared explicitly or dissallowed, as
- // otherwise "ptr1 == ptr2" will compile but do the wrong thing (i.e., convert
- // to Testable and then do the comparison).
- //
- // C++11 provides for "explicit operator bool()", however it is currently
- // banned due to MSVS2013. https://chromium-cpp.appspot.com/#core-blacklist
- 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();
« no previous file with comments | « no previous file | base/threading/thread_unittest.cc » ('j') | chrome/browser/themes/theme_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698