mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-19 13:26:45 +00:00
[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:
parent
195015cf67
commit
3c28ce6bec
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user