Issue 130656
Summary Mark std::expected as [[nodiscard]]
Labels new issue
Assignees
Reporter 2LoS
    I think it may be problematic to discard the result of a function that uses `std::expected` for error handling. It is the equivalent of enclosing an exception-throwing function call in a try-catch block, where any caught exception is just ignored.

```cpp
try {
 func();
}
catch(...) {}
```

The language allows it to happen without any ceremony. It should, of course, be possible to write the ceremony explicitly.

```cpp
(void)func();
```

The way to make this happen is marking `std::expected` as nodiscard. For example, *[Microsoft STL](https://github.com/microsoft/STL/pull/5174)* and *martinmoene/expected-lite* have already done it. Also libc++ has fixed its tests to support the case in which `std::expected` be marked as nodiscard, even if its own library has not marked it yet.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to