Commit 576710ca authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

Add FOLLY_NODISCARD for [[nodiscard]] attribute when it exists,...

Add FOLLY_NODISCARD for [[nodiscard]] attribute when it exists, FOLLY_WARN_UNUSED_RESULT uses FOLLY_NODISCARD.

Summary: The `nodiscard` attribute was added to standard C++ in C++17. Prefer the standard formulation when it is available; otherwise, use `__attribute__((__warn_unused_result__))` on compilers that support the GNU extensions, and `_Check_return_` on MSVC. The old `FOLLY_WARN_UNUSED_RESULT` is now expands to `FOLLY_NODISCARD`.

Reviewed By: yfeldblum

Differential Revision: D5105137

fbshipit-source-id: 9aa22e81cd9f0b89f9343433aeae3ba365227ccb
parent 3e0ea102
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment