diff --git a/libcxx/include/__system_error/system_error.h b/libcxx/include/__system_error/system_error.h --- a/libcxx/include/__system_error/system_error.h +++ b/libcxx/include/__system_error/system_error.h @@ -13,6 +13,7 @@ #include <__config> #include <__system_error/error_category.h> #include <__system_error/error_code.h> +#include <__verbose_abort> #include #include @@ -39,6 +40,14 @@ }; _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 diff --git a/libcxx/src/print.cpp b/libcxx/src/print.cpp --- a/libcxx/src/print.cpp +++ b/libcxx/src/print.cpp @@ -47,12 +47,7 @@ __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 diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -290,14 +290,8 @@ { } -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