Description
It is 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.
try {
func();
}
catch(...) {}
The language allows it to happen without any ceremony. It should, of course, be possible to write the ceremony explicitly.
(void)func();
The way to make this happen is marking std::expected
as nodiscard. For example, Microsoft STL 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.