2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_SYSTEM_ERROR
11 #define _LIBCPP_SYSTEM_ERROR
22 virtual ~error_category() noexcept;
24 constexpr error_category();
25 error_category(const error_category&) = delete;
26 error_category& operator=(const error_category&) = delete;
28 virtual const char* name() const noexcept = 0;
29 virtual error_condition default_error_condition(int ev) const noexcept;
30 virtual bool equivalent(int code, const error_condition& condition) const noexcept;
31 virtual bool equivalent(const error_code& code, int condition) const noexcept;
32 virtual string message(int ev) const = 0;
34 bool operator==(const error_category& rhs) const noexcept;
35 bool operator!=(const error_category& rhs) const noexcept; // removed in C++20
36 bool operator<(const error_category& rhs) const noexcept; // removed in C++20
37 strong_ordering operator<=>(const error_category& rhs) const noexcept; // C++20
40 const error_category& generic_category() noexcept;
41 const error_category& system_category() noexcept;
43 template <class T> struct is_error_code_enum
44 : public false_type {};
46 template <class T> struct is_error_condition_enum
47 : public false_type {};
50 inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
53 inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
59 error_code() noexcept;
60 error_code(int val, const error_category& cat) noexcept;
61 template <class ErrorCodeEnum>
62 error_code(ErrorCodeEnum e) noexcept;
65 void assign(int val, const error_category& cat) noexcept;
66 template <class ErrorCodeEnum>
67 error_code& operator=(ErrorCodeEnum e) noexcept;
68 void clear() noexcept;
71 int value() const noexcept;
72 const error_category& category() const noexcept;
73 error_condition default_error_condition() const noexcept;
74 string message() const;
75 explicit operator bool() const noexcept;
78 // non-member functions:
79 template <class charT, class traits>
80 basic_ostream<charT,traits>&
81 operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
87 error_condition() noexcept;
88 error_condition(int val, const error_category& cat) noexcept;
89 template <class ErrorConditionEnum>
90 error_condition(ErrorConditionEnum e) noexcept;
93 void assign(int val, const error_category& cat) noexcept;
94 template <class ErrorConditionEnum>
95 error_condition& operator=(ErrorConditionEnum e) noexcept;
96 void clear() noexcept;
99 int value() const noexcept;
100 const error_category& category() const noexcept;
101 string message() const noexcept;
102 explicit operator bool() const noexcept;
106 : public runtime_error
109 system_error(error_code ec, const string& what_arg);
110 system_error(error_code ec, const char* what_arg);
111 system_error(error_code ec);
112 system_error(int ev, const error_category& ecat, const string& what_arg);
113 system_error(int ev, const error_category& ecat, const char* what_arg);
114 system_error(int ev, const error_category& ecat);
116 const error_code& code() const noexcept;
117 const char* what() const noexcept;
120 template <> struct is_error_condition_enum<errc>
123 error_code make_error_code(errc e) noexcept;
124 error_condition make_error_condition(errc e) noexcept;
126 // Comparison operators:
127 bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
128 bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
129 bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; // removed in C++20
130 bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
131 bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; // removed in C++20
132 bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; // removed in C++20
133 bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; // removed in C++20
134 bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; // removed in C++20
135 bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; // removed in C++20
136 bool operator<(const error_code& lhs, const error_code& rhs) noexcept; // removed in C++20
137 strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept; // C++20
138 strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept; // C++20
140 template <> struct hash<std::error_code>;
141 template <> struct hash<std::error_condition>;
147 #include <__assert> // all public C++ headers provide the assertion handler
149 #include <__system_error/errc.h>
150 #include <__system_error/error_category.h>
151 #include <__system_error/error_code.h>
152 #include <__system_error/error_condition.h>
153 #include <__system_error/system_error.h>
156 // standard-mandated includes
158 // [system.error.syn]
161 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
162 # pragma GCC system_header
165 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
169 # include <type_traits>
172 #endif // _LIBCPP_SYSTEM_ERROR