[libc++] Adds __throw_system_error overload.

This was mention in D150044 and D154995 that this would be useful.
This addresses the last review coment of D150044.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D156019
This commit is contained in:
Mark de Wever 2023-07-18 22:06:00 +02:00
parent 195015cf67
commit 3c28ce6bec
3 changed files with 12 additions and 14 deletions

View File

@ -13,6 +13,7 @@
#include <__config>
#include <__system_error/error_category.h>
#include <__system_error/error_code.h>
#include <__verbose_abort>
#include <stdexcept>
#include <string>
@ -39,6 +40,14 @@ public:
};
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __throw_system_error(error_code __ec, const char* __what_arg) {
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
throw system_error(__ec, __what_arg);
#else
_LIBCPP_VERBOSE_ABORT(
"system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", __ec.value(), __what_arg);
#endif
}
_LIBCPP_END_NAMESPACE_STD

View File

@ -47,12 +47,7 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst
__view.size(),
nullptr,
nullptr) == 0) {
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
// There is no __throw_system_error overload that takes an error code.
throw system_error{filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output"};
# else // _LIBCPP_HAS_NO_EXCEPTIONS
std::abort();
# endif // _LIBCPP_HAS_NO_EXCEPTIONS
__throw_system_error(filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output");
}
}
# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS

View File

@ -290,14 +290,8 @@ system_error::~system_error() noexcept
{
}
void
__throw_system_error(int ev, const char* what_arg)
{
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
throw system_error(error_code(ev, system_category()), what_arg);
#else
_LIBCPP_VERBOSE_ABORT("system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg);
#endif
void __throw_system_error(int ev, const char* what_arg) {
std::__throw_system_error(error_code(ev, system_category()), what_arg);
}
_LIBCPP_END_NAMESPACE_STD