From 388fe425c783b1994608789842503ec756327913 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Thu, 6 Apr 2017 04:32:27 -0700 Subject: [PATCH] Make WARN_UNUSED_RESULT a no-op on gcc Because on gcc, cast to void doesn't silence the warning. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 Also add an RTC_ prefix to the macro instead of only defining it if it wasn't already defined, to ensure that we always get our own version. BUG=none Review-Url: https://codereview.webrtc.org/2797983003 Cr-Commit-Position: refs/heads/master@{#17563} --- webrtc/base/swap_queue.h | 4 ++-- .../audio_coding/codecs/ilbc/cb_construct.h | 2 +- .../modules/audio_coding/codecs/ilbc/decode.h | 2 +- .../codecs/ilbc/decode_residual.h | 2 +- .../audio_coding/codecs/ilbc/get_cd_vec.h | 2 +- webrtc/typedefs.h | 19 ++++++++++--------- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/webrtc/base/swap_queue.h b/webrtc/base/swap_queue.h index 1851309bd7..acb16b49a0 100644 --- a/webrtc/base/swap_queue.h +++ b/webrtc/base/swap_queue.h @@ -118,7 +118,7 @@ class SwapQueue { // When specified, the T given in *input must pass the ItemVerifier() test. // The contents of *input after the call are then also guaranteed to pass the // ItemVerifier() test. - bool Insert(T* input) WARN_UNUSED_RESULT { + bool Insert(T* input) RTC_WARN_UNUSED_RESULT { RTC_DCHECK(input); rtc::CritScope cs(&crit_queue_); @@ -151,7 +151,7 @@ class SwapQueue { // empty). When specified, The T given in *output must pass the ItemVerifier() // test and the contents of *output after the call are then also guaranteed to // pass the ItemVerifier() test. - bool Remove(T* output) WARN_UNUSED_RESULT { + bool Remove(T* output) RTC_WARN_UNUSED_RESULT { RTC_DCHECK(output); rtc::CritScope cs(&crit_queue_); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_construct.h b/webrtc/modules/audio_coding/codecs/ilbc/cb_construct.h index 34c0d1b777..12df628211 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_construct.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_construct.h @@ -34,6 +34,6 @@ bool WebRtcIlbcfix_CbConstruct( int16_t* mem, /* (i) Buffer for codevector construction */ size_t lMem, /* (i) Length of buffer */ size_t veclen /* (i) Length of vector */ - ) WARN_UNUSED_RESULT; + ) RTC_WARN_UNUSED_RESULT; #endif diff --git a/webrtc/modules/audio_coding/codecs/ilbc/decode.h b/webrtc/modules/audio_coding/codecs/ilbc/decode.h index f45fedd7b3..2d05182612 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/decode.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/decode.h @@ -33,6 +33,6 @@ int WebRtcIlbcfix_DecodeImpl( structure */ int16_t mode /* (i) 0: bad packet, PLC, 1: normal */ - ) WARN_UNUSED_RESULT; + ) RTC_WARN_UNUSED_RESULT; #endif diff --git a/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.h b/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.h index 38f896ec6d..e3fb7f78cb 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.h @@ -35,6 +35,6 @@ bool WebRtcIlbcfix_DecodeResidual( int16_t* decresidual, /* (o) decoded residual frame */ int16_t* syntdenum /* (i) the decoded synthesis filter coefficients */ - ) WARN_UNUSED_RESULT; + ) RTC_WARN_UNUSED_RESULT; #endif diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_cd_vec.h b/webrtc/modules/audio_coding/codecs/ilbc/get_cd_vec.h index b770e761d7..a5abb5e916 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/get_cd_vec.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/get_cd_vec.h @@ -31,6 +31,6 @@ bool WebRtcIlbcfix_GetCbVec( size_t index, /* (i) Codebook index */ size_t lMem, /* (i) Length of codebook buffer */ size_t cbveclen /* (i) Codebook vector length */ - ) WARN_UNUSED_RESULT; + ) RTC_WARN_UNUSED_RESULT; #endif diff --git a/webrtc/typedefs.h b/webrtc/typedefs.h index bc48c08290..bd0bee75c2 100644 --- a/webrtc/typedefs.h +++ b/webrtc/typedefs.h @@ -65,17 +65,18 @@ // Annotate a function indicating the caller must examine the return value. // Use like: -// int foo() WARN_UNUSED_RESULT; -// To explicitly ignore a result, see |ignore_result()| in . -// TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and -// libjingle are merged. -#if !defined(WARN_UNUSED_RESULT) -#if defined(__GNUC__) || defined(__clang__) -#define WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) +// int foo() RTC_WARN_UNUSED_RESULT; +// To explicitly ignore a result, cast to void. +// TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17. +#if defined(__clang__) +#define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) +#elif defined(__GNUC__) +// gcc has a __warn_unused_result__ attribute, but you can't quiet it by +// casting to void, so we don't use it. +#define RTC_WARN_UNUSED_RESULT #else -#define WARN_UNUSED_RESULT +#define RTC_WARN_UNUSED_RESULT #endif -#endif // WARN_UNUSED_RESULT // Put after a variable that might not be used, to prevent compiler warnings: // int result ATTRIBUTE_UNUSED = DoSomething();