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

Unified Diff: base/memory/ref_counted.h

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 2 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 | « base/files/important_file_writer_unittest.cc ('k') | base/memory/weak_ptr.h » ('j') | no next file with comments »
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 ba7e657389d1d88e9cdfe75282ee17e250ec2fde..f088589b1c2121545a7b0d31fc62c18d413e8abc 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -249,8 +249,12 @@ class scoped_refptr {
ptr_->Release();
}
+ // Allow scoped_refptr<T> to be used in boolean expressions, but not
+ // implicitly convertible to a real bool (which is dangerous).
+ typedef T* scoped_refptr::*Testable;
+ operator Testable() const { return ptr_ ? &scoped_refptr::ptr_ : NULL; }
+
T* get() const { return ptr_; }
- operator T*() const { return ptr_; }
T* operator->() const {
assert(ptr_ != NULL);
return ptr_;
« no previous file with comments | « base/files/important_file_writer_unittest.cc ('k') | base/memory/weak_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698