[libcxx-commits] [libcxx] [libc++] P3798R1: The unexpected in std::expected (PR #204826)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 20 14:59:26 PDT 2026
================
@@ -825,6 +825,10 @@ class expected : private __expected_base<_Tp, _Err> {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
+# if _LIBCPP_STD_VER >= 29
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_error() const noexcept { return !this->has_value(); }
----------------
Zingam wrote:
`[[nodiscard]]` needs a test.
`noexcept` needs a test, usually "static_assert(noexcept(exp.has_error()))` instead of declaring a concept.
Test return type with `std::same_as<bool> decltype(auto) error = exp.has_error()`.
You also need to update the `void` specialization here: https://github.com/llvm/llvm-project/blob/3c5f0c2d3e00a22a275f404bac29ce62c69d95d5/libcxx/include/__expected/expected.h#L1600 as seen in the Draft here: https://github.com/cplusplus/draft/pull/9127/changes
https://github.com/llvm/llvm-project/pull/204826
More information about the libcxx-commits
mailing list