[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17

Marshall Clow via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 24 10:56:03 PDT 2018


mclow.lists added a comment.

In https://reviews.llvm.org/D45179#1077055, @thakis wrote:

> So you're happy with this opt-in version?


I'm happy with an opt-in mechanism, yes.
This one is not quite right yet.

BTW, I expect a //large// set of calls in the standard library to get marked as `[[nodiscard]]` in Rapperswil.



================
Comment at: include/__config:1016
+// because GCC does not silence them via (void) cast.
+#if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17
+#  define _LIBCPP_NODISCARD [[nodiscard]]
----------------
`[[nodiscard]]` is a C++17 feature. This test should be `>=`, not `>`.


================
Comment at: include/__config:1026
+    (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_FORCE_NODISCARD))
+#  define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
 #else
----------------
I wouldn't change this; just leave it as `[[nodiscard]]`


Repository:
  rCXX libc++

https://reviews.llvm.org/D45179





More information about the cfe-commits mailing list