libstdc++: Remove dg-options "-std=gnu++20" from 20_utils tests
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / optional / relops / 96269.cc
blobddb4be30fd766d195644e33a628717e7efa454b1
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
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 } }
20 #include <optional>
22 struct X
24 template <typename T>
25 bool operator==(const T&) /* not const */ { return false; }
27 template <typename T>
28 bool operator!=(const T&) /* not const */ { return false; }
30 template <typename T>
31 bool operator<(const T&) /* not const */ { return false; }
33 template <typename T>
34 bool operator>(const T&) /* not const */ { return false; }
36 template <typename T>
37 bool operator<=(const T&) /* not const */ { return false; }
39 template <typename T>
40 bool operator>=(const T&) /* not const */ { return false; }
43 void test01()
45 // PR 96269 optional comparison with nullopt fails
46 std::optional<X> x;
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;
56 template<typename T>
57 concept optional_lt_cmp
58 = requires(std::optional<T> o, T t) { { o < t } -> std::same_as<bool>; };
60 template<typename T>
61 concept optional_gt_cmp
62 = requires(std::optional<T> o, T t) { { o > t } -> std::same_as<bool>; };
64 template<typename T>
65 concept optional_le_cmp
66 = requires(std::optional<T> o, T t) { { o <= t } -> std::same_as<bool>; };
68 template<typename T>
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> );