[libcxx-commits] [libcxx] [llvm] [libc++] Implement P3379R0 Constrain `std::expected` equality operators (PR #135759)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 3 05:45:23 PDT 2025
================
@@ -1139,8 +1140,15 @@ class expected : private __expected_base<_Tp, _Err> {
// [expected.object.eq], equality operators
template <class _T2, class _E2>
+ _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y)
requires(!is_void_v<_T2>)
- _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) {
+# if _LIBCPP_STD_VER >= 26
+ && requires {
+ { *__x == *__y } -> __core_convertible_to<bool>;
----------------
frederick-vs-ja wrote:
I don't think it's intended to allow such a return type. However, the core language rules "accidentally" permits such a weird return type when there's no additional constraints/`static_assert`'s.
IMO, P3379R0 and P2944R3 (for `optional`, `variant`, and `expected`) should only add constraints that reflects the "mandates" in the `return` statements. It seems that the original intent of operators was that natural mandates in the `return` statements should work for these operators, and thus no additional `static_assert` would be necessary.
https://github.com/llvm/llvm-project/pull/135759
More information about the libcxx-commits
mailing list