[libcxx-commits] [libcxx] 3c28ce6 - [libc++] Adds __throw_system_error overload.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 29 10:09:46 PDT 2023
Author: Mark de Wever
Date: 2023-08-29T19:08:18+02:00
New Revision: 3c28ce6bec7699670a483b8cb254fe620e533eeb
URL: https://github.com/llvm/llvm-project/commit/3c28ce6bec7699670a483b8cb254fe620e533eeb
DIFF: https://github.com/llvm/llvm-project/commit/3c28ce6bec7699670a483b8cb254fe620e533eeb.diff
LOG: [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
Added:
Modified:
libcxx/include/__system_error/system_error.h
libcxx/src/print.cpp
libcxx/src/system_error.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__system_error/system_error.h b/libcxx/include/__system_error/system_error.h
index b41b73e32a4a21..362e67505658cb 100644
--- 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 <stdexcept>
#include <string>
@@ -39,6 +40,14 @@ class _LIBCPP_EXPORTED_FROM_ABI system_error : public runtime_error {
};
_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
index 3d8a4c291ee53c..a581dd37fe788a 100644
--- a/libcxx/src/print.cpp
+++ b/libcxx/src/print.cpp
@@ -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
diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp
index 7800a79370ee70..670375c73ca8ac 100644
--- a/libcxx/src/system_error.cpp
+++ b/libcxx/src/system_error.cpp
@@ -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
More information about the libcxx-commits
mailing list