[libcxx-commits] [libcxx] [libc++] mark `std::expected` as `nodiscard` (PR #130820)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 28 02:31:44 PDT 2025


huixie90 wrote:

> > Is there any paper adding ā€˜[[candiscard]]’ floating around ? I’d much prefer to making it possible for the function owner to make the function possible to discard the returned value, before we adding the blanket nodiscard for everyone. Imagine if we make printf nodiscard for the reason of not checking the error code? It will simply end up with lots of #pragma gcc diagnostic
> 
> Yes, there is [P2992R1](https://wg21.link/P2992R1) proposing the `[[discard]]` attribute. However, that depends on the ability to put attributes on expressions, which is a rather large and controversial step to take. Because of this, in St. Louis (2024-06) P2992R1 was [rejected](https://github.com/cplusplus/papers/issues/1665#issuecomment-2192729264) by EWG with a rather split vote.

Thank is not the same though. that `[[discard]]` is somewhat similar to `[[maybe_unused]]` and it is intended to be used by the function caller. What I really like is for authors of the functions that return `expected` to override the class level `expected`'s `[[nodiscard]]`, and to say that my function's `expected` can be discarded

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


More information about the libcxx-commits mailing list