Add FOLLY_NODISCARD for [[nodiscard]] attribute when it exists, FOLLY_WARN_UNUSED_RES...
[folly.git] / folly / Portability.h
index 51032fdacd43addc99388e9f765cca2e246e77a4..49d48f071f8022628c8ebaa232b91c95371629b6 100644 (file)
@@ -71,13 +71,21 @@ constexpr bool kHasUnalignedAccess = false;
 #endif
 
 // warn unused result
+#if defined(__has_cpp_attribute)
+#if __has_cpp_attribute(nodiscard)
+#define FOLLY_NODISCARD [[nodiscard]]
+#endif
+#endif
+#if !defined FOLLY_NODISCARD
 #if defined(_MSC_VER) && (_MSC_VER >= 1700)
-#define FOLLY_WARN_UNUSED_RESULT _Check_return_
+#define FOLLY_NODISCARD _Check_return_
 #elif defined(__clang__) || defined(__GNUC__)
-#define FOLLY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
+#define FOLLY_NODISCARD __attribute__((__warn_unused_result__))
 #else
-#define FOLLY_WARN_UNUSED_RESULT
+#define FOLLY_NODISCARD
+#endif
 #endif
+#define FOLLY_WARN_UNUSED_RESULT FOLLY_NODISCARD
 
 // target
 #ifdef _MSC_VER