177 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_SYSTEM_ERROR11#define _LIBCPP_SYSTEM_ERROR12 13/*14 system_error synopsis15 16namespace std17{18 19class error_category20{21public:22 virtual ~error_category() noexcept;23 24 constexpr error_category();25 error_category(const error_category&) = delete;26 error_category& operator=(const error_category&) = delete;27 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;33 34 bool operator==(const error_category& rhs) const noexcept;35 bool operator!=(const error_category& rhs) const noexcept; // removed in C++2036 bool operator<(const error_category& rhs) const noexcept; // removed in C++2037 strong_ordering operator<=>(const error_category& rhs) const noexcept; // C++2038};39 40const error_category& generic_category() noexcept;41const error_category& system_category() noexcept;42 43template <class T> struct is_error_code_enum44 : public false_type {};45 46template <class T> struct is_error_condition_enum47 : public false_type {};48 49template <class _Tp>50inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++1751 52template <class _Tp>53inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++1754 55class error_code56{57public:58 // constructors:59 error_code() noexcept;60 error_code(int val, const error_category& cat) noexcept;61 template <class ErrorCodeEnum>62 error_code(ErrorCodeEnum e) noexcept;63 64 // modifiers: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;69 70 // observers: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;76};77 78// non-member functions:79template <class charT, class traits>80 basic_ostream<charT,traits>&81 operator<<(basic_ostream<charT,traits>& os, const error_code& ec);82 83class error_condition84{85public:86 // constructors:87 error_condition() noexcept;88 error_condition(int val, const error_category& cat) noexcept;89 template <class ErrorConditionEnum>90 error_condition(ErrorConditionEnum e) noexcept;91 92 // modifiers: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;97 98 // observers:99 int value() const noexcept;100 const error_category& category() const noexcept;101 string message() const noexcept;102 explicit operator bool() const noexcept;103};104 105class system_error106 : public runtime_error107{108public: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);115 116 const error_code& code() const noexcept;117 const char* what() const noexcept;118};119 120template <> struct is_error_condition_enum<errc>121 : true_type { }122 123error_code make_error_code(errc e) noexcept;124error_condition make_error_condition(errc e) noexcept;125 126// Comparison operators:127bool operator==(const error_code& lhs, const error_code& rhs) noexcept;128bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;129bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; // removed in C++20130bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;131bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; // removed in C++20132bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; // removed in C++20133bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; // removed in C++20134bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; // removed in C++20135bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; // removed in C++20136bool operator<(const error_code& lhs, const error_code& rhs) noexcept; // removed in C++20137strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept; // C++20138strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept; // C++20139 140template <> struct hash<std::error_code>;141template <> struct hash<std::error_condition>;142 143} // std144 145*/146 147#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)148# include <__cxx03/system_error>149#else150# include <__config>151# include <__system_error/errc.h>152# include <__system_error/error_category.h>153# include <__system_error/error_code.h>154# include <__system_error/error_condition.h>155# include <__system_error/system_error.h>156# include <version>157 158// standard-mandated includes159 160// [system.error.syn]161# include <compare>162 163# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)164# pragma GCC system_header165# endif166 167# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20168# include <cstdint>169# include <cstring>170# include <limits>171# include <optional>172# include <type_traits>173# endif174#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)175 176#endif // _LIBCPP_SYSTEM_ERROR177