Skip to content

Commit 51f0b80

Browse files
committed
[libc++] Formats the sytem_error headers.
Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D147886
1 parent c95b322 commit 51f0b80

File tree

5 files changed

+182
-277
lines changed

5 files changed

+182
-277
lines changed

libcxx/include/__system_error/error_category.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,46 @@ class _LIBCPP_TYPE_VIS error_code;
2525

2626
class _LIBCPP_HIDDEN __do_message;
2727

28-
class _LIBCPP_TYPE_VIS error_category
29-
{
28+
class _LIBCPP_TYPE_VIS error_category {
3029
public:
31-
virtual ~error_category() _NOEXCEPT;
30+
virtual ~error_category() _NOEXCEPT;
3231

3332
#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
34-
error_category() noexcept;
33+
error_category() noexcept;
3534
#else
36-
_LIBCPP_INLINE_VISIBILITY
37-
_LIBCPP_CONSTEXPR_SINCE_CXX14 error_category() _NOEXCEPT = default;
35+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 error_category() _NOEXCEPT = default;
3836
#endif
39-
error_category(const error_category&) = delete;
40-
error_category& operator=(const error_category&) = delete;
37+
error_category(const error_category&) = delete;
38+
error_category& operator=(const error_category&) = delete;
4139

42-
virtual const char* name() const _NOEXCEPT = 0;
43-
virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
44-
virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
45-
virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
46-
virtual string message(int __ev) const = 0;
40+
virtual const char* name() const _NOEXCEPT = 0;
41+
virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
42+
virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
43+
virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
44+
virtual string message(int __ev) const = 0;
4745

48-
_LIBCPP_INLINE_VISIBILITY
49-
bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
46+
_LIBCPP_INLINE_VISIBILITY bool operator==(const error_category& __rhs) const _NOEXCEPT { return this == &__rhs; }
5047

5148
#if _LIBCPP_STD_VER >= 20
5249

53-
_LIBCPP_HIDE_FROM_ABI
54-
strong_ordering operator<=>(const error_category& __rhs) const noexcept {return compare_three_way()(this, std::addressof(__rhs));}
50+
_LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const error_category& __rhs) const noexcept {
51+
return compare_three_way()(this, std::addressof(__rhs));
52+
}
5553

56-
#else // _LIBCPP_STD_VER >= 20
54+
#else // _LIBCPP_STD_VER >= 20
5755

58-
_LIBCPP_INLINE_VISIBILITY
59-
bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
56+
_LIBCPP_INLINE_VISIBILITY bool operator!=(const error_category& __rhs) const _NOEXCEPT { return !(*this == __rhs); }
6057

61-
_LIBCPP_INLINE_VISIBILITY
62-
bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
58+
_LIBCPP_INLINE_VISIBILITY bool operator<(const error_category& __rhs) const _NOEXCEPT { return this < &__rhs; }
6359

6460
#endif // _LIBCPP_STD_VER >= 20
6561

66-
friend class _LIBCPP_HIDDEN __do_message;
62+
friend class _LIBCPP_HIDDEN __do_message;
6763
};
6864

69-
class _LIBCPP_HIDDEN __do_message
70-
: public error_category
71-
{
65+
class _LIBCPP_HIDDEN __do_message : public error_category {
7266
public:
73-
string message(int __ev) const override;
67+
string message(int __ev) const override;
7468
};
7569

7670
_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;

libcxx/include/__system_error/error_code.h

Lines changed: 81 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -27,163 +27,119 @@
2727
_LIBCPP_BEGIN_NAMESPACE_STD
2828

2929
template <class _Tp>
30-
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
31-
: public false_type {};
30+
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public false_type {};
3231

3332
#if _LIBCPP_STD_VER >= 17
3433
template <class _Tp>
3534
inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
3635
#endif
3736

3837
namespace __adl_only {
39-
// Those cause ADL to trigger but they are not viable candidates,
40-
// so they are never actually selected.
41-
void make_error_code() = delete;
38+
// Those cause ADL to trigger but they are not viable candidates,
39+
// so they are never actually selected.
40+
void make_error_code() = delete;
4241
} // namespace __adl_only
4342

44-
class _LIBCPP_TYPE_VIS error_code
45-
{
46-
int __val_;
47-
const error_category* __cat_;
43+
class _LIBCPP_TYPE_VIS error_code {
44+
int __val_;
45+
const error_category* __cat_;
46+
4847
public:
49-
_LIBCPP_INLINE_VISIBILITY
50-
error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
51-
52-
_LIBCPP_INLINE_VISIBILITY
53-
error_code(int __val, const error_category& __cat) _NOEXCEPT
54-
: __val_(__val), __cat_(&__cat) {}
55-
56-
template <class _Ep>
57-
_LIBCPP_INLINE_VISIBILITY
58-
error_code(_Ep __e,
59-
typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr
60-
) _NOEXCEPT
61-
{
62-
using __adl_only::make_error_code;
63-
*this = make_error_code(__e);
64-
}
65-
66-
_LIBCPP_INLINE_VISIBILITY
67-
void assign(int __val, const error_category& __cat) _NOEXCEPT
68-
{
69-
__val_ = __val;
70-
__cat_ = &__cat;
71-
}
72-
73-
template <class _Ep>
74-
_LIBCPP_INLINE_VISIBILITY
75-
typename enable_if
76-
<
77-
is_error_code_enum<_Ep>::value,
78-
error_code&
79-
>::type
80-
operator=(_Ep __e) _NOEXCEPT
81-
{
82-
using __adl_only::make_error_code;
83-
*this = make_error_code(__e);
84-
return *this;
85-
}
86-
87-
_LIBCPP_INLINE_VISIBILITY
88-
void clear() _NOEXCEPT
89-
{
90-
__val_ = 0;
91-
__cat_ = &system_category();
92-
}
93-
94-
_LIBCPP_INLINE_VISIBILITY
95-
int value() const _NOEXCEPT {return __val_;}
96-
97-
_LIBCPP_INLINE_VISIBILITY
98-
const error_category& category() const _NOEXCEPT {return *__cat_;}
99-
100-
_LIBCPP_INLINE_VISIBILITY
101-
error_condition default_error_condition() const _NOEXCEPT
102-
{return __cat_->default_error_condition(__val_);}
103-
104-
string message() const;
105-
106-
_LIBCPP_INLINE_VISIBILITY
107-
explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
48+
_LIBCPP_INLINE_VISIBILITY error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
49+
50+
_LIBCPP_INLINE_VISIBILITY error_code(int __val, const error_category& __cat) _NOEXCEPT
51+
: __val_(__val),
52+
__cat_(&__cat) {}
53+
54+
template <class _Ep>
55+
_LIBCPP_INLINE_VISIBILITY
56+
error_code(_Ep __e, typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr) _NOEXCEPT {
57+
using __adl_only::make_error_code;
58+
*this = make_error_code(__e);
59+
}
60+
61+
_LIBCPP_INLINE_VISIBILITY void assign(int __val, const error_category& __cat) _NOEXCEPT {
62+
__val_ = __val;
63+
__cat_ = &__cat;
64+
}
65+
66+
template <class _Ep>
67+
_LIBCPP_INLINE_VISIBILITY typename enable_if< is_error_code_enum<_Ep>::value, error_code& >::type
68+
operator=(_Ep __e) _NOEXCEPT {
69+
using __adl_only::make_error_code;
70+
*this = make_error_code(__e);
71+
return *this;
72+
}
73+
74+
_LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {
75+
__val_ = 0;
76+
__cat_ = &system_category();
77+
}
78+
79+
_LIBCPP_INLINE_VISIBILITY int value() const _NOEXCEPT { return __val_; }
80+
81+
_LIBCPP_INLINE_VISIBILITY const error_category& category() const _NOEXCEPT { return *__cat_; }
82+
83+
_LIBCPP_INLINE_VISIBILITY error_condition default_error_condition() const _NOEXCEPT {
84+
return __cat_->default_error_condition(__val_);
85+
}
86+
87+
string message() const;
88+
89+
_LIBCPP_INLINE_VISIBILITY explicit operator bool() const _NOEXCEPT { return __val_ != 0; }
10890
};
10991

110-
inline _LIBCPP_INLINE_VISIBILITY
111-
error_code
112-
make_error_code(errc __e) _NOEXCEPT
113-
{
114-
return error_code(static_cast<int>(__e), generic_category());
92+
inline _LIBCPP_INLINE_VISIBILITY error_code make_error_code(errc __e) _NOEXCEPT {
93+
return error_code(static_cast<int>(__e), generic_category());
11594
}
11695

117-
inline _LIBCPP_INLINE_VISIBILITY
118-
bool
119-
operator==(const error_code& __x, const error_code& __y) _NOEXCEPT
120-
{
121-
return __x.category() == __y.category() && __x.value() == __y.value();
96+
inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_code& __x, const error_code& __y) _NOEXCEPT {
97+
return __x.category() == __y.category() && __x.value() == __y.value();
12298
}
12399

124-
inline _LIBCPP_INLINE_VISIBILITY
125-
bool
126-
operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
127-
{
128-
return __x.category().equivalent(__x.value(), __y)
129-
|| __y.category().equivalent(__x, __y.value());
100+
inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT {
101+
return __x.category().equivalent(__x.value(), __y) || __y.category().equivalent(__x, __y.value());
130102
}
131103

132104
#if _LIBCPP_STD_VER <= 17
133-
inline _LIBCPP_INLINE_VISIBILITY
134-
bool
135-
operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
136-
{
137-
return __y == __x;
105+
inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT {
106+
return __y == __x;
138107
}
139108
#endif
140109

141110
#if _LIBCPP_STD_VER <= 17
142111

143-
inline _LIBCPP_INLINE_VISIBILITY
144-
bool
145-
operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
146-
{return !(__x == __y);}
147-
148-
inline _LIBCPP_INLINE_VISIBILITY
149-
bool
150-
operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
151-
{return !(__x == __y);}
152-
153-
inline _LIBCPP_INLINE_VISIBILITY
154-
bool
155-
operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
156-
{return !(__x == __y);}
157-
158-
inline _LIBCPP_INLINE_VISIBILITY
159-
bool
160-
operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
161-
{
162-
return __x.category() < __y.category()
163-
|| (__x.category() == __y.category() && __x.value() < __y.value());
112+
inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT {
113+
return !(__x == __y);
114+
}
115+
116+
inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT {
117+
return !(__x == __y);
118+
}
119+
120+
inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT {
121+
return !(__x == __y);
122+
}
123+
124+
inline _LIBCPP_INLINE_VISIBILITY bool operator<(const error_code& __x, const error_code& __y) _NOEXCEPT {
125+
return __x.category() < __y.category() || (__x.category() == __y.category() && __x.value() < __y.value());
164126
}
165127

166-
#else // _LIBCPP_STD_VER <= 17
128+
#else // _LIBCPP_STD_VER <= 17
167129

168-
inline _LIBCPP_HIDE_FROM_ABI strong_ordering
169-
operator<=>(const error_code& __x, const error_code& __y) noexcept
170-
{
171-
if (auto __c = __x.category() <=> __y.category(); __c != 0)
172-
return __c;
173-
return __x.value() <=> __y.value();
130+
inline _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const error_code& __x, const error_code& __y) noexcept {
131+
if (auto __c = __x.category() <=> __y.category(); __c != 0)
132+
return __c;
133+
return __x.value() <=> __y.value();
174134
}
175135

176136
#endif // _LIBCPP_STD_VER <= 17
177137

178138
template <>
179-
struct _LIBCPP_TEMPLATE_VIS hash<error_code>
180-
: public __unary_function<error_code, size_t>
181-
{
182-
_LIBCPP_INLINE_VISIBILITY
183-
size_t operator()(const error_code& __ec) const _NOEXCEPT
184-
{
185-
return static_cast<size_t>(__ec.value());
186-
}
139+
struct _LIBCPP_TEMPLATE_VIS hash<error_code> : public __unary_function<error_code, size_t> {
140+
_LIBCPP_INLINE_VISIBILITY size_t operator()(const error_code& __ec) const _NOEXCEPT {
141+
return static_cast<size_t>(__ec.value());
142+
}
187143
};
188144

189145
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)