1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do compile { target c++20 } }
25 bool operator==(const T
&) /* not const */ { return false; }
28 bool operator!=(const T
&) /* not const */ { return false; }
31 bool operator<(const T
&) /* not const */ { return false; }
34 bool operator>(const T
&) /* not const */ { return false; }
37 bool operator<=(const T
&) /* not const */ { return false; }
40 bool operator>=(const T
&) /* not const */ { return false; }
45 // PR 96269 optional comparison with nullopt fails
47 bool eq
[[maybe_unused
]] = std::nullopt
== x
;
49 bool ne
[[maybe_unused
]] = std::nullopt
!= x
;
50 bool lt
[[maybe_unused
]] = std::nullopt
< x
;
51 bool gt
[[maybe_unused
]] = std::nullopt
> x
;
52 bool le
[[maybe_unused
]] = std::nullopt
<= x
;
53 bool ge
[[maybe_unused
]] = std::nullopt
>= x
;
57 concept optional_lt_cmp
58 = requires(std::optional
<T
> o
, T t
) { { o
< t
} -> std::same_as
<bool>; };
61 concept optional_gt_cmp
62 = requires(std::optional
<T
> o
, T t
) { { o
> t
} -> std::same_as
<bool>; };
65 concept optional_le_cmp
66 = requires(std::optional
<T
> o
, T t
) { { o
<= t
} -> std::same_as
<bool>; };
69 concept optional_ge_cmp
70 = requires(std::optional
<T
> o
, T t
) { { o
>= t
} -> std::same_as
<bool>; };
72 static_assert( ! optional_lt_cmp
<X
> );
73 static_assert( ! optional_gt_cmp
<X
> );
74 static_assert( ! optional_le_cmp
<X
> );
75 static_assert( ! optional_ge_cmp
<X
> );