[libcxx-commits] [libcxx] [libc++][RFC] Document when to apply [[nodiscard]] (PR #84000)

Jonathan Wakely via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 13 09:43:20 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?
+====================================================
+
----------------
jwakely wrote:

IMHO if you're using the function like that then I think being forced to explicitly cast the result to void makes it clearer for readers that you're using it in an unusual way.

https://github.com/llvm/llvm-project/pull/84000


More information about the libcxx-commits mailing list