[libcxx-commits] [libcxx] [libc++][RFC] Document when to apply [[nodiscard]] (PR #84000)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 13 11:08:50 PDT 2024
================
@@ -0,0 +1,34 @@
+======================================
+``[[nodiscard]]`` extensions in libc++
+======================================
+
+Libc++ adds ``[[nodiscard]]`` to functions in a lot more places than the
+standard does. Any applications of ``[[nodiscard]]`` that aren't required by the
+standard written as ``_LIBCPP_NODISCARD_EXT`` to make it possible to disable
+them. This can be done by defining ``_LIBCPP_DISABLE_NODISCARD_EXT``.
+
+When should ``[[nodiscard]]`` be added to functions?
+====================================================
+
----------------
mordante wrote:
I don't feel it's poor style per se. In this case you could use `std::expected`. But I've seen similar creative usage of `std` algorithms in code bases.
IMO the cast to void is a hint to the reader something odd is going on and the algorithm is used in a different way. So I'm still happy to make these `[[nodiscard]]`.
https://github.com/llvm/llvm-project/pull/84000
More information about the libcxx-commits
mailing list