From 576710cae8be19a1e35371860ab85a7bba02d085 Mon Sep 17 00:00:00 2001
From: Eric Niebler <eniebler@fb.com>
Date: Tue, 23 May 2017 09:01:31 -0700
Subject: [PATCH] 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
---
 folly/Portability.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/folly/Portability.h b/folly/Portability.h
index 51032fda..49d48f07 100644
--- a/folly/Portability.h
+++ b/folly/Portability.h
@@ -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
-- 
2.34.1