add FOLLY_MAYBE_UNUSED
authorVictor Gao <vgao@fb.com>
Tue, 18 Jul 2017 20:19:24 +0000 (13:19 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 18 Jul 2017 20:25:14 +0000 (13:25 -0700)
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

index 752a82dd7911f743409f7794e34f989a33e9fb0f..542e271811aa49cc9e92af51a6a80b127fedb7ab 100644 (file)
 #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.