From 24791b60f40b77f44e21ed878e918b897c9bb8f2 Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Mon, 3 May 2010 18:41:25 +0000 Subject: Add a macro to ignore the return value of a function. The more typical (void)(function()) does not work with GCC when explicitly marking the -Wunused-value attribute on a function. I plan to land the fix for bug 42904 in stages: 1) add this macro 2) fix some instance (either a misuse of release(), or just add this macro to it) 3) fix some instance (either a misuse of release(), or just add this macro to it) .... n - 1) fix some instance (either a misuse of release(), or just add this macro to it) n) enable the WARN_UNUSED_VALUE attribute on {scoped_ptr,scoped_ptr_malloc,scoped_array}.release() BUG=42904 TEST=none Review URL: http://codereview.chromium.org/1794012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46252 0039d316-1c4b-4281-b951-d872f2087c98 --- base/basictypes.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'base') diff --git a/base/basictypes.h b/base/basictypes.h index 1e44303..f6b92ec 100644 --- a/base/basictypes.h +++ b/base/basictypes.h @@ -327,6 +327,17 @@ inline Dest bit_cast(const Source& source) { return dest; } +// Used to explicitly mark the return value of a function as unused. If you are +// really sure you don't want to do anything with the return value of a function +// that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: +// +// scoped_ptr my_var = ...; +// if (TakeOwnership(my_var.get()) == SUCCESS) +// IGNORE_RESULT(my_var.release()); +// +#define IGNORE_RESULT(x) \ + do { size_t unused = sizeof(x); unused = 0; } while (false) + // The following enum should be used only as a constructor argument to indicate // that the variable has static storage class, and that the constructor should // do nothing to its state. It indicates to the reader that it is legal to -- cgit v1.1