From dd9afc0b5666f35137c850c8cc625750ae49c223 Mon Sep 17 00:00:00 2001 From: "agl@chromium.org" Date: Fri, 21 Nov 2008 23:58:09 +0000 Subject: Generate a warning if the return value of FilePath::Append is ignored. There's currently a GCC bug which stops this working for return values which have a destructor. Hopefully this will help someone in the future, with future versions of GCC. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38172 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31742 Review URL: http://codereview.chromium.org/11494 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5871 0039d316-1c4b-4281-b951-d872f2087c98 --- base/compiler_specific.h | 10 ++++++++-- base/file_path.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'base') diff --git a/base/compiler_specific.h b/base/compiler_specific.h index c9b7535..11777fb 100644 --- a/base/compiler_specific.h +++ b/base/compiler_specific.h @@ -53,7 +53,7 @@ code \ MSVC_POP_WARNING() -#else // COMPILER_MSVC +#else // Not MSVC #define MSVC_SUPPRESS_WARNING(n) #define MSVC_PUSH_DISABLE_WARNING(n) @@ -65,5 +65,11 @@ #endif // COMPILER_MSVC -#endif // BASE_COMPILER_SPECIFIC_H_ +#if defined(COMPILER_GCC) +#define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else // Not GCC +#define WARN_UNUSED_RESULT +#endif + +#endif // BASE_COMPILER_SPECIFIC_H_ diff --git a/base/file_path.h b/base/file_path.h index 6bb426f..1ebb299 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -67,6 +67,7 @@ #include +#include "base/compiler_specific.h" #include "base/basictypes.h" // Windows-style drive letter support and pathname separator characters can be @@ -141,7 +142,7 @@ class FilePath { // If this object's path is kCurrentDirectory, a new FilePath corresponding // only to |component| is returned. |component| must be a relative path; // it is an error to pass an absolute path. - FilePath Append(const StringType& component) const; + FilePath Append(const StringType& component) const WARN_UNUSED_RESULT; // Returns true if this FilePath contains an absolute path. On Windows, an // absolute path begins with either a drive letter specification followed by -- cgit v1.1