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

Yihe Li via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 25 01:09:02 PDT 2025


Mick235711 wrote:

> While I like the idea in general, I really dislike that there is no way for the user to say "it's fine to discard the expected from this function", so we force the user to either not use expected when it may be OK to discard, or add casts to void on every single call site. Neither option seems great.

Well, in C++26, users will be able to do
```cpp
std::ignore = some_func_returning_expected();
```
to signify that it is OK to discard an `std::expected` return, which seems much more readable than casting to void. (libc++ had already implemented this change to `std::ignore`)

Whether this is an acceptable solution to force on users is up for debate, though.

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


More information about the libcxx-commits mailing list