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

Side by Side Diff: base/memory/ref_counted.h

Issue 10874054: Add WARN_UNUSED_RESULT to scoped_refptr::release. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Don't assign NULL to pointer to scoped_refptr. Created 8 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MEMORY_REF_COUNTED_H_ 5 #ifndef BASE_MEMORY_REF_COUNTED_H_
6 #define BASE_MEMORY_REF_COUNTED_H_ 6 #define BASE_MEMORY_REF_COUNTED_H_
7 7
8 #include <cassert> 8 #include <cassert>
9 9
10 #include "base/atomic_ref_count.h" 10 #include "base/atomic_ref_count.h"
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/compiler_specific.h"
12 #include "base/threading/thread_collision_warner.h" 13 #include "base/threading/thread_collision_warner.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 namespace subtle { 17 namespace subtle {
17 18
18 class BASE_EXPORT RefCountedBase { 19 class BASE_EXPORT RefCountedBase {
19 public: 20 public:
20 bool HasOneRef() const { return ref_count_ == 1; } 21 bool HasOneRef() const { return ref_count_ == 1; }
21 22
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 T* operator->() const { 254 T* operator->() const {
254 assert(ptr_ != NULL); 255 assert(ptr_ != NULL);
255 return ptr_; 256 return ptr_;
256 } 257 }
257 258
258 // Release a pointer. 259 // Release a pointer.
259 // The return value is the current pointer held by this object. 260 // The return value is the current pointer held by this object.
260 // If this object holds a NULL pointer, the return value is NULL. 261 // If this object holds a NULL pointer, the return value is NULL.
261 // After this operation, this object will hold a NULL pointer, 262 // After this operation, this object will hold a NULL pointer,
262 // and will not own the object any more. 263 // and will not own the object any more.
263 T* release() { 264 T* release() WARN_UNUSED_RESULT {
264 T* retVal = ptr_; 265 T* retVal = ptr_;
265 ptr_ = NULL; 266 ptr_ = NULL;
266 return retVal; 267 return retVal;
267 } 268 }
268 269
269 scoped_refptr<T>& operator=(T* p) { 270 scoped_refptr<T>& operator=(T* p) {
270 // AddRef first so that self assignment should work 271 // AddRef first so that self assignment should work
271 if (p) 272 if (p)
272 p->AddRef(); 273 p->AddRef();
273 T* old_ptr = ptr_; 274 T* old_ptr = ptr_;
(...skipping 27 matching lines...) Expand all
301 }; 302 };
302 303
303 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 304 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
304 // having to retype all the template arguments 305 // having to retype all the template arguments
305 template <typename T> 306 template <typename T>
306 scoped_refptr<T> make_scoped_refptr(T* t) { 307 scoped_refptr<T> make_scoped_refptr(T* t) {
307 return scoped_refptr<T>(t); 308 return scoped_refptr<T>(t);
308 } 309 }
309 310
310 #endif // BASE_MEMORY_REF_COUNTED_H_ 311 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698