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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 5 10:55:44 PST 2024


philnik777 wrote:

> First of all thanks for working on this! As mentioned in #83695 there is a paper [P3122R0](https://wg21.link/p3122r0) "[[nodiscard]] should be Recommended Practice" by @jwakely and there is another paper [P2422R0](https://wg21.link/p2422r0) "Remove nodiscard annotations from the standard library specification" that proposes to drop all `[[nodiscard]]`s from the draft.
> 
> These papers are likely to be discussed in a few weeks during the Tokyo meeting. So I would propose to wait until that has been discussed; it might affect this RFC. Even when these papers are not accepted we should look at P3122R0 it has recommended practices we could use as guideline in our documentation.
> 
> Note I'm in favour of using `[[nodiscard]]` more in libc++ and the direction of these papers.

Thanks for bringing them up. I agree that this may change things, but I also think that discussing this beforehand within the library also makes a lot of sense, since "look, one implementation already does it, the second one is working on getting `[[nodiscard]]` in lots of places, and the third one's main maintainer is proposing this stuff" is a really good argument (got a bit wordy). If we talk about it beforehand, we have thought about it already quite a bit and can hopefully give good reasons to add `[[nodiscard]]` to some functions and not to others.

>From looking at the list of P3122R0 I think we want to add comparison operators. Everything else should already be covered™.

FWIW I also very much agree with the sentiment of the papers.


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


More information about the libcxx-commits mailing list