[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
Sun Mar 15 18:30:53 PDT 2026
================
@@ -446,6 +446,16 @@ class __expected_base {
_LIBCPP_NO_UNIQUE_ADDRESS __conditional_no_unique_address<__allow_reusing_expected_tail_padding, __repr> __repr_;
};
+// Helper to handle cases for LWG4366 Heterogeneous comparison of ``expected`` may be ill-formed
+// Where the comparison may produce a value that is a type that is not bool, and is implicitly
+// convertible to bool, but not explicitly.
+template <typename _ImplictlyBool>
+constexpr bool __into_bool(_ImplictlyBool&& __b)
+ requires __core_convertible_to<_ImplictlyBool, bool>
+{
+ return __b;
+}
----------------
frederick-vs-ja wrote:
I don't think we need a template here. Also, it might be more convenient to make this function `noexcept` for future exception specification strengthening.
```suggestion
constexpr bool __into_bool(bool __b) noexcept {
return __b;
}
```
https://github.com/llvm/llvm-project/pull/185342
More information about the libcxx-commits
mailing list