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

Yihe Li via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 26 13:16:00 PDT 2025


Mick235711 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.

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


More information about the libcxx-commits mailing list