From: Victor Gao Date: Tue, 18 Jul 2017 20:19:24 +0000 (-0700) Subject: add FOLLY_MAYBE_UNUSED X-Git-Tag: v2017.07.17.01~1 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=b10cedceae3f3fc098a69b2c67f9a8b119166c48 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 --- 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.