| 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_code e1; |
| 27 |
std::error_code e2(std::make_error_code(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 |
VERIFY( (e1 <=> e2) == (e1.category() <=> e2.category()) ); |
| 36 |
|
| 37 |
VERIFY( e1 == e1 ); |
| 38 |
VERIFY( !(e1 == e2) ); |
| 39 |
|
| 40 |
VERIFY( !(e1 < e1) ); |
| 41 |
VERIFY( !(e2 < e2) ); |
| 42 |
|
| 43 |
const __gnu_test::test_category cat; |
| 44 |
std::error_code e3(e2.value(), cat); |
| 45 |
|
| 46 |
VERIFY( std::is_neq(e2 <=> e3) ); |
| 47 |
VERIFY( std::is_lt(e2 <=> e3) || std::is_gt(e2 <=> e3) ); |
| 48 |
VERIFY( (e2 <=> e3) == (e2.category() <=> e3.category()) ); |
| 49 |
|
| 50 |
VERIFY( !(e2 == e3) ); |
| 51 |
|
| 52 |
VERIFY( !(e3 < e3) ); |
| 53 |
VERIFY( (e2 < e3) == (e2.category() < e3.category()) ); |
| 54 |
|
| 55 |
std::error_code e4(std::make_error_code(std::errc::invalid_argument)); |
| 56 |
|
| 57 |
VERIFY( std::is_neq(e4 <=> e2) ); |
| 58 |
VERIFY( std::is_lt(e4 <=> e2) || std::is_gt(e4 <=> e2) ); |
| 59 |
VERIFY( (e4 <=> e2) == (e4.value() <=> e2.value()) ); |
| 60 |
} |
| 61 |
|
| 62 |
int main() |
| 63 |
{ |
| 64 |
test01(); |
| 65 |
} |