From b10cedceae3f3fc098a69b2c67f9a8b119166c48 Mon Sep 17 00:00:00 2001 From: Victor Gao Date: Tue, 18 Jul 2017 13:19:24 -0700 Subject: [PATCH] add FOLLY_MAYBE_UNUSED Summary: This adds a macro `FOLLY_MAYBE_UNUSED` in `folly/CppAttributes.h` that can be used to suppress `-Wunused` warnings. Reviewed By: yfeldblum Differential Revision: D5444742 fbshipit-source-id: b16e8efefd76282498ad6114bac9548064cf38d5 --- folly/CppAttributes.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/folly/CppAttributes.h b/folly/CppAttributes.h index 752a82dd..542e2718 100644 --- a/folly/CppAttributes.h +++ b/folly/CppAttributes.h @@ -53,6 +53,26 @@ #define FOLLY_FALLTHROUGH #endif +/** + * Maybe_unused indicates that a function, variable or parameter might or + * might not be used, e.g. + * + * int foo(FOLLY_MAYBE_UNUSED int x) { + * #ifdef USE_X + * return x; + * #else + * return 0; + * #endif + * } + */ +#if FOLLY_HAS_CPP_ATTRIBUTE(maybe_unused) +#define FOLLY_MAYBE_UNUSED [[maybe_unused]] +#elif FOLLY_HAS_CPP_ATTRIBUTE(gnu::unused) +#define FOLLY_MAYBE_UNUSED [[gnu::unused]] +#else +#define FOLLY_MAYBE_UNUSED +#endif + /** * Nullable indicates that a return value or a parameter may be a `nullptr`, * e.g. -- 2.34.1