[libcxx-commits] [libcxx] [libc++][RFC] Document when to apply [[nodiscard]] (PR #84000)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 28 08:45: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?
+====================================================
+
+``[[nodiscard]]`` should be applied to functions
+
+- where it is most likely a correctness issue when discarding the return value.
+ For example a locking constructor in ``unique_lock``.
----------------
ldionne wrote:
```suggestion
- where discarding the return value is most likely a correctness issue.
For example a locking constructor in ``unique_lock``.
```
https://github.com/llvm/llvm-project/pull/84000
More information about the libcxx-commits
mailing list