[libcxx-commits] [PATCH] D156019: [libc++] Adds __throw_system_error overload.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 23 08:46:06 PDT 2023


Mordante updated this revision to Diff 552739.
Mordante added a comment.

Rebased and addresses review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156019/new/

https://reviews.llvm.org/D156019

Files:
  libcxx/include/__system_error/system_error.h
  libcxx/src/print.cpp
  libcxx/src/system_error.cpp


Index: libcxx/src/system_error.cpp
===================================================================
--- libcxx/src/system_error.cpp
+++ 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
Index: libcxx/src/print.cpp
===================================================================
--- libcxx/src/print.cpp
+++ 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
Index: libcxx/include/__system_error/system_error.h
===================================================================
--- libcxx/include/__system_error/system_error.h
+++ 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 @@
 };
 
 _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
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156019.552739.patch
Type: text/x-patch
Size: 2369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230823/4581e4e7/attachment.bin>


More information about the libcxx-commits mailing list