diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 16:20:32 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 16:20:32 +0000 |
commit | f5059510f0e8b33c33850dbdd77d595b2bb9ad79 (patch) | |
tree | 20227e14c20d3ab4f365a75fc460a0af7ecebc68 /base/compiler_specific.h | |
parent | 2907525c5676868aa09104f84575ea27fca156cf (diff) | |
download | chromium_src-f5059510f0e8b33c33850dbdd77d595b2bb9ad79.zip chromium_src-f5059510f0e8b33c33850dbdd77d595b2bb9ad79.tar.gz chromium_src-f5059510f0e8b33c33850dbdd77d595b2bb9ad79.tar.bz2 |
Add an OVERRIDE macro to our list of compiler-specific annotations.
While I'm at it, add docs and examples to the other annotations.
Review URL: http://codereview.chromium.org/3581016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/compiler_specific.h')
-rw-r--r-- | base/compiler_specific.h | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/base/compiler_specific.h b/base/compiler_specific.h index ce93998..5917882 100644 --- a/base/compiler_specific.h +++ b/base/compiler_specific.h @@ -67,33 +67,53 @@ #endif // COMPILER_MSVC +// Annotate a variable indicating it's ok if the variable is not used. +// (Typically used to silence a compiler warning when the assignment +// is important for some other reason.) +// Use like: +// int x ALLOW_UNUSED = ...; #if defined(COMPILER_GCC) - #define ALLOW_UNUSED __attribute__((unused)) +#else +#define ALLOW_UNUSED +#endif + +// Annotate a virtual method indicating it must be overriding a virtual +// method in the parent class. +// Use like: +// virtual void foo() OVERRIDE; +#if defined(COMPILER_MSVC) +#define OVERRIDE override +#else +#define OVERRIDE +#endif + +// Annotate a function indicating the caller must examine the return value. +// Use like: +// int foo() WARN_UNUSED_RESULT; +#if defined(COMPILER_GCC) #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define WARN_UNUSED_RESULT +#endif // Tell the compiler a function is using a printf-style format string. // |format_param| is the one-based index of the format string parameter; // |dots_param| is the one-based index of the "..." parameter. // For v*printf functions (which take a va_list), pass 0 for dots_param. // (This is undocumented but matches what the system C headers do.) +#if defined(COMPILER_GCC) #define PRINTF_FORMAT(format_param, dots_param) \ __attribute__((format(printf, format_param, dots_param))) +#else +#define PRINTF_FORMAT(format_param, dots_param) +#endif // WPRINTF_FORMAT is the same, but for wide format strings. -// This doesn't appear to yet be implemented. +// This doesn't appear to yet be implemented in any compiler. // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 . #define WPRINTF_FORMAT(format_param, dots_param) // If available, it would look like: // __attribute__((format(wprintf, format_param, dots_param))) -#else // Not GCC - -#define ALLOW_UNUSED -#define WARN_UNUSED_RESULT -#define PRINTF_FORMAT(x, y) -#define WPRINTF_FORMAT(x, y) - -#endif - #endif // BASE_COMPILER_SPECIFIC_H_ |