| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-additional-options "-static-libstdc++" { target *-*-mingw* } } |
| 3 |
|
| 4 |
// Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 5 |
// |
| 6 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 7 |
// software; you can redistribute it and/or modify it under the |
| 8 |
// terms of the GNU General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3, or (at your option) |
| 10 |
// any later version. |
| 11 |
|
| 12 |
// This library is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
|
| 17 |
// You should have received a copy of the GNU General Public License along |
| 18 |
// with this library; see the file COPYING3. If not see |
| 19 |
// <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
#include <system_error> |
| 22 |
#include <testsuite_error.h> |
| 23 |
|
| 24 |
namespace adl |
| 25 |
{ |
| 26 |
struct Error { }; |
| 27 |
|
| 28 |
const Error err; |
| 29 |
|
| 30 |
struct category : std::error_category |
| 31 |
{ |
| 32 |
const char* name() const noexcept override { return "adl"; } |
| 33 |
std::string message(int) const { return ""; } |
| 34 |
}; |
| 35 |
|
| 36 |
const category cat; |
| 37 |
|
| 38 |
std::error_condition |
| 39 |
make_error_condition(Error) { return std::error_condition(999, cat); } |
| 40 |
} |
| 41 |
|
| 42 |
template<> struct std::is_error_condition_enum<adl::Error> : std::true_type { }; |
| 43 |
|
| 44 |
void test01() |
| 45 |
{ |
| 46 |
// 1 error_condition() |
| 47 |
std::error_condition e1; |
| 48 |
VERIFY( e1.value() == 0 ); |
| 49 |
VERIFY( e1.category() == std::generic_category() ); |
| 50 |
|
| 51 |
// 2 error_condition(int, const error_category&) |
| 52 |
const __gnu_test::test_category cat; |
| 53 |
std::error_condition e2(e1.value(), cat); |
| 54 |
VERIFY( e2.value() == e1.value() ); |
| 55 |
VERIFY( e2.category() == cat ); |
| 56 |
|
| 57 |
// 3 error_condition(const error_condition&) |
| 58 |
std::error_condition e3(std::errc::operation_not_supported); |
| 59 |
VERIFY( e3.value() == int(std::errc::operation_not_supported) ); |
| 60 |
VERIFY( e3.category() == std::generic_category() ); |
| 61 |
|
| 62 |
// 4 error_condition(ErrorConditionEnum) |
| 63 |
std::error_condition e4(adl::err); |
| 64 |
VERIFY( e4.value() == 999 ); |
| 65 |
VERIFY( e4.category() == adl::cat ); |
| 66 |
} |
| 67 |
|
| 68 |
int main() |
| 69 |
{ |
| 70 |
test01(); |
| 71 |
return 0; |
| 72 |
} |