summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 01:03:53 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 01:03:53 +0000
commit8d09c271e3b13bac6d9aab9244e588fc88486c5f (patch)
tree2a5ed80f3119d9de7c1558f0acb170bdcb5e7c72
parent04a8a104d96c96ee64bdbeb8dd1ed515e6521c5f (diff)
downloadchromium_src-8d09c271e3b13bac6d9aab9244e588fc88486c5f.zip
chromium_src-8d09c271e3b13bac6d9aab9244e588fc88486c5f.tar.gz
chromium_src-8d09c271e3b13bac6d9aab9244e588fc88486c5f.tar.bz2
Warn about unused results on release() for three scoped_ptr classes.
Depends on cleaning up existing uses of release(). BUG=42904 TEST=compile Review URL: http://codereview.chromium.org/1783015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46649 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/scoped_ptr.h8
-rw-r--r--base/scoped_ptr_unittest.cc2
2 files changed, 6 insertions, 4 deletions
diff --git a/base/scoped_ptr.h b/base/scoped_ptr.h
index 34e4666a..c716e77 100644
--- a/base/scoped_ptr.h
+++ b/base/scoped_ptr.h
@@ -44,6 +44,8 @@
#include <stdlib.h>
#include <cstddef>
+#include "base/compiler_specific.h"
+
// A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T>
// automatically deletes the pointer it holds (if any).
// That is, scoped_ptr<T> owns the T object that it points to.
@@ -113,7 +115,7 @@ class scoped_ptr {
// If this object holds a NULL pointer, the return value is NULL.
// After this operation, this object will hold a NULL pointer,
// and will not own the object any more.
- C* release() {
+ C* release() WARN_UNUSED_RESULT {
C* retVal = ptr_;
ptr_ = NULL;
return retVal;
@@ -220,7 +222,7 @@ class scoped_array {
// If this object holds a NULL pointer, the return value is NULL.
// After this operation, this object will hold a NULL pointer,
// and will not own the object any more.
- C* release() {
+ C* release() WARN_UNUSED_RESULT {
C* retVal = array_;
array_ = NULL;
return retVal;
@@ -337,7 +339,7 @@ class scoped_ptr_malloc {
// If this object holds a NULL pointer, the return value is NULL.
// After this operation, this object will hold a NULL pointer,
// and will not own the object any more.
- C* release() {
+ C* release() WARN_UNUSED_RESULT {
C* tmp = ptr_;
ptr_ = NULL;
return tmp;
diff --git a/base/scoped_ptr_unittest.cc b/base/scoped_ptr_unittest.cc
index 9ea2289..99b1bc0 100644
--- a/base/scoped_ptr_unittest.cc
+++ b/base/scoped_ptr_unittest.cc
@@ -115,7 +115,7 @@ TEST(ScopedPtrTest, ScopedArray) {
{
scoped_array<ConDecLogger> scoper;
EXPECT_FALSE(scoper.get());
- scoper.release();
+ EXPECT_FALSE(scoper.release());
EXPECT_FALSE(scoper.get());
scoper.reset();
EXPECT_FALSE(scoper.get());