Skip to content

Commit 805ac6a

Browse files
committed
[libc++] P3379R1: Constrain 'std::expected' equality operators
1 parent 02d1d91 commit 805ac6a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

libcxx/test/std/utilities/expected/expected.expected/equality/equality.other_expected.pass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
template <class T1, class T2>
2424
concept CanCompare = requires(T1 t1, T2 t2) { t1 == t2; };
2525

26-
struct Foo {};
27-
static_assert(!CanCompare<Foo, Foo>);
26+
struct NonComparable {};
27+
static_assert(!CanCompare<NonComparable, NonComparable>);
2828

2929
static_assert(CanCompare<std::expected<int, int>, std::expected<int, int>>);
3030
static_assert(CanCompare<std::expected<int, int>, std::expected<short, short>>);
3131

32+
#if _LIBCPP_STD_VER >= 26
33+
static_assert(!CanCompare<std::expected<int, int>, std::expected<void, int>>);
34+
static_assert(!CanCompare<std::expected<NonComparable, int>, std::expected<NonComparable, int>>);
35+
static_assert(!CanCompare<std::expected<int, NonComparable>, std::expected<int, NonComparable>>);
36+
static_assert(!CanCompare<std::expected<NonComparable, NonComparable>, std::expected<NonComparable, NonComparable>>);
37+
#endif
38+
3239
constexpr bool test() {
3340
// x.has_value() && y.has_value()
3441
{

libcxx/test/std/utilities/expected/expected.void/equality/equality.other_expected.pass.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@
2323
template <class T1, class T2>
2424
concept CanCompare = requires(T1 t1, T2 t2) { t1 == t2; };
2525

26-
struct Foo {};
27-
static_assert(!CanCompare<Foo, Foo>);
26+
struct NonComparable {};
27+
static_assert(!CanCompare<NonComparable, NonComparable>);
2828

2929
static_assert(CanCompare<std::expected<void, int>, std::expected<void, int>>);
3030
static_assert(CanCompare<std::expected<void, int>, std::expected<void, short>>);
3131

32+
#if _LIBCPP_STD_VER >= 26
33+
static_assert(!CanCompare<std::expected<void, int>, std::expected<int, int>>);
34+
static_assert(!CanCompare<std::expected<void, NonComparable>, std::expected<void, NonComparable>>);
35+
#endif
36+
3237
constexpr bool test() {
3338
// x.has_value() && y.has_value()
3439
{

0 commit comments

Comments
 (0)