[libcxx-commits] [libcxx] [libc++] Resolve LWG4366: Heterogeneous comparison of `expected` may be ill-formed (PR #185342)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 17 01:24:34 PDT 2026


================
@@ -1169,7 +1176,7 @@ class expected : private __expected_base<_Tp, _Err> {
     }
 #  endif
   {
-    return __x.__has_val() && static_cast<bool>(__x.__val() == __v);
+    return __x.__has_val() && __into_bool(__x.__val() == __v);
----------------
frederick-vs-ja wrote:

I think we should use `std::` if we decide to invent the `__into_bool` function, ditto below.

```suggestion
    return __x.__has_val() && std::__into_bool(__x.__val() == __v);
```

Pedantically, the return type of `operator==` is allowed to be ADL-unfriendly. E.g.

```C++
template <class T>
struct holder { T t; };

struct incomplete;

template <class T>
struct convsrc {
  bool b_;
  constexpr operator bool() const { return b_; }
};

using testing_convsrc = convsrc<holder<incomplete>>;
```

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


More information about the libcxx-commits mailing list