Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LWG-3629 make_error_code and make_error_condition are customization points #3272

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stl/inc/future
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public:
void _Abandon() { // abandon shared state
unique_lock<mutex> _Lock(_Mtx);
if (!_Already_has_stored_result()) { // queue exception
future_error _Fut(make_error_code(future_errc::broken_promise));
future_error _Fut(_STD make_error_code(future_errc::broken_promise));
_Set_exception_raw(_STD make_exception_ptr(_Fut), &_Lock, false);
}
}
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public:
~promise() noexcept {
if (_MyPromise._Is_valid() && !_MyPromise._Is_ready() && !_MyPromise._Is_ready_at_thread_exit()) {
// exception if destroyed before function object returns
future_error _Fut(make_error_code(future_errc::broken_promise));
future_error _Fut(_STD make_error_code(future_errc::broken_promise));
_MyPromise._Get_state()._Set_exception(_STD make_exception_ptr(_Fut), false);
}
}
Expand Down Expand Up @@ -1242,7 +1242,7 @@ public:
~promise() noexcept {
if (_MyPromise._Is_valid() && !_MyPromise._Is_ready() && !_MyPromise._Is_ready_at_thread_exit()) {
// exception if destroyed before function object returns
future_error _Fut(make_error_code(future_errc::broken_promise));
future_error _Fut(_STD make_error_code(future_errc::broken_promise));
_MyPromise._Get_state()._Set_exception(_STD make_exception_ptr(_Fut), false);
}
}
Expand Down Expand Up @@ -1296,7 +1296,7 @@ public:
~promise() noexcept {
if (_MyPromise._Is_valid() && !_MyPromise._Is_ready() && !_MyPromise._Is_ready_at_thread_exit()) {
// exception if destroyed before function object returns
future_error _Fut(make_error_code(future_errc::broken_promise));
future_error _Fut(_STD make_error_code(future_errc::broken_promise));
_MyPromise._Get_state()._Set_exception(_STD make_exception_ptr(_Fut), false);
}
}
Expand Down
21 changes: 13 additions & 8 deletions stl/inc/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ _INLINE_VAR constexpr bool is_error_condition_enum_v = is_error_condition_enum<_

_EXPORT_STD class error_code;
_EXPORT_STD class error_condition;
_EXPORT_STD _NODISCARD error_code make_error_code(errc) noexcept;
_EXPORT_STD _NODISCARD error_code make_error_code(io_errc) noexcept;
_EXPORT_STD _NODISCARD error_condition make_error_condition(errc) noexcept;
_EXPORT_STD _NODISCARD error_condition make_error_condition(io_errc) noexcept;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

namespace _Ensure_adl {
void make_error_code() = delete;
void make_error_condition() = delete;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other reviewers: this change doesn't need to workaround the MSVC bug that was an issue for the CPOs (#3215 (comment)), that bug only affects names in requires-expressions. (No change requested.)

} // namespace _Ensure_adl

_EXPORT_STD class error_category;

Expand Down Expand Up @@ -168,7 +169,8 @@ public:

template <class _Enum, enable_if_t<is_error_code_enum_v<_Enum>, int> = 0>
error_code(_Enum _Errcode) noexcept : _Myval(0), _Mycat(nullptr) {
*this = make_error_code(_Errcode); // using ADL
using _Ensure_adl::make_error_code;
*this = make_error_code(_Errcode); // intentional ADL
}

void assign(int _Val, const error_category& _Cat) noexcept {
Expand All @@ -178,7 +180,8 @@ public:

template <class _Enum, enable_if_t<is_error_code_enum_v<_Enum>, int> = 0>
error_code& operator=(_Enum _Errcode) noexcept {
*this = make_error_code(_Errcode); // using ADL
using _Ensure_adl::make_error_code;
*this = make_error_code(_Errcode); // intentional ADL
return *this;
}

Expand Down Expand Up @@ -259,7 +262,8 @@ public:

template <class _Enum, enable_if_t<is_error_condition_enum_v<_Enum>, int> = 0>
error_condition(_Enum _Errcode) noexcept : _Myval(0), _Mycat(nullptr) {
*this = make_error_condition(_Errcode); // using ADL
using _Ensure_adl::make_error_condition;
*this = make_error_condition(_Errcode); // intentional ADL
}

void assign(int _Val, const error_category& _Cat) noexcept {
Expand All @@ -269,7 +273,8 @@ public:

template <class _Enum, enable_if_t<is_error_condition_enum_v<_Enum>, int> = 0>
error_condition& operator=(_Enum _Errcode) noexcept {
*this = make_error_condition(_Errcode); // using ADL
using _Ensure_adl::make_error_condition;
*this = make_error_condition(_Errcode); // intentional ADL
return *this;
}

Expand Down
40 changes: 20 additions & 20 deletions stl/inc/valarray
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ _NODISCARD valarray<_Ty> abs(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = abs(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = abs(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1176,7 +1176,7 @@ _NODISCARD valarray<_Ty> acos(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = acos(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = acos(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1186,7 +1186,7 @@ _NODISCARD valarray<_Ty> asin(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = asin(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = asin(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1196,7 +1196,7 @@ _NODISCARD valarray<_Ty> atan(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = atan(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = atan(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1206,7 +1206,7 @@ _NODISCARD valarray<_Ty> atan2(const valarray<_Ty>& _Left, const valarray<_Ty>&
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = atan2(_Left[_Idx], _Right[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = atan2(_Left[_Idx], _Right[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1216,7 +1216,7 @@ _NODISCARD valarray<_Ty> atan2(const valarray<_Ty>& _Left, const typename valarr
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = atan2(_Left[_Idx], _Right); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = atan2(_Left[_Idx], _Right); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1226,7 +1226,7 @@ _NODISCARD valarray<_Ty> atan2(const typename valarray<_Ty>::value_type& _Left,
const size_t _Size = _Right.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = atan2(_Left, _Right[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = atan2(_Left, _Right[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1236,7 +1236,7 @@ _NODISCARD valarray<_Ty> cos(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = cos(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = cos(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1246,7 +1246,7 @@ _NODISCARD valarray<_Ty> cosh(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = cosh(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = cosh(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1256,7 +1256,7 @@ _NODISCARD valarray<_Ty> exp(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = exp(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = exp(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1266,7 +1266,7 @@ _NODISCARD valarray<_Ty> log(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = log(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = log(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1276,7 +1276,7 @@ _NODISCARD valarray<_Ty> log10(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = log10(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = log10(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1286,7 +1286,7 @@ _NODISCARD valarray<_Ty> pow(const valarray<_Ty>& _Left, const valarray<_Ty>& _R
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = pow(_Left[_Idx], _Right[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = pow(_Left[_Idx], _Right[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1296,7 +1296,7 @@ _NODISCARD valarray<_Ty> pow(const valarray<_Ty>& _Left, const typename valarray
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = pow(_Left[_Idx], _Right); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = pow(_Left[_Idx], _Right); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1306,7 +1306,7 @@ _NODISCARD valarray<_Ty> pow(const typename valarray<_Ty>::value_type& _Left, co
const size_t _Size = _Right.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = pow(_Left, _Right[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = pow(_Left, _Right[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1316,7 +1316,7 @@ _NODISCARD valarray<_Ty> sin(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = sin(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = sin(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1326,7 +1326,7 @@ _NODISCARD valarray<_Ty> sinh(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = sinh(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = sinh(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1336,7 +1336,7 @@ _NODISCARD valarray<_Ty> sqrt(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = sqrt(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = sqrt(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1346,7 +1346,7 @@ _NODISCARD valarray<_Ty> tan(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = tan(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = tan(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand All @@ -1356,7 +1356,7 @@ _NODISCARD valarray<_Ty> tanh(const valarray<_Ty>& _Left) {
const size_t _Size = _Left.size();
valarray<_Ty> _Ans(_Size);
for (size_t _Idx = 0; _Idx < _Size; ++_Idx) {
_Ans[_Idx] = tanh(_Left[_Idx]); // using ADL, N4835 [valarray.transcend]/1
_Ans[_Idx] = tanh(_Left[_Idx]); // intentional ADL, N4835 [valarray.transcend]/1
}
return _Ans;
}
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xiosbase
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ public:

class failure : public system_error { // base of all iostreams exceptions
public:
explicit failure(const string& _Message, const error_code& _Errcode = make_error_code(io_errc::stream))
explicit failure(const string& _Message, const error_code& _Errcode = _STD make_error_code(io_errc::stream))
: system_error(_Errcode, _Message) {} // construct with message

explicit failure(const char* _Message, const error_code& _Errcode = make_error_code(io_errc::stream))
explicit failure(const char* _Message, const error_code& _Errcode = _STD make_error_code(io_errc::stream))
: system_error(_Errcode, _Message) {} // construct with message

#if !_HAS_EXCEPTIONS
Expand Down
Loading