Debian Codegraph @

libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc

raw
1 // Copyright (C) 2020-2025 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.
8
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.
13
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/>.
17
18 // { dg-do run { target c++20 } }
19
20 #include <system_error>
21 #include <testsuite_error.h>
22
23 void
24 test01()
25 {
26 std::error_condition e1;
27 std::error_condition e2(std::errc::operation_not_supported);
28
29 VERIFY( std::is_eq(e1 <=> e1) );
30 VERIFY( std::is_lteq(e1 <=> e1) );
31 VERIFY( std::is_gteq(e1 <=> e1) );
32
33 VERIFY( std::is_neq(e1 <=> e2) );
34 VERIFY( std::is_lt(e1 <=> e2) || std::is_gt(e1 <=> e2) );
35 // e1.category() == e2.category(), so comparison depends on values:
36 VERIFY( (e1 <=> e2) == (e1.value() <=> e2.value()) );
37
38 VERIFY( e1 == e1 );
39 VERIFY( !(e1 == e2) );
40
41 VERIFY( !(e1 < e1) );
42 VERIFY( !(e2 < e2) );
43
44 const __gnu_test::test_category cat;
45 std::error_condition e3(e2.value(), cat);
46
47 VERIFY( std::is_neq(e2 <=> e3) );
48 VERIFY( std::is_lt(e2 <=> e3) || std::is_gt(e2 <=> e3) );
49 VERIFY( (e2 <=> e3) == (e2.category() <=> e3.category()) );
50
51 VERIFY( !(e2 == e3) );
52
53 VERIFY( !(e3 < e3) );
54 VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
55 }
56
57 int main()
58 {
59 test01();
60 }