[libcxx-commits] [libcxx] [libc++] Avoid including <string> in <mutex> (PR #116254)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 14 09:18:16 PST 2024
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/116254
>From cd30f5cc16c30359ab6121982a59f6599bd47c5a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 14 Nov 2024 17:30:23 +0100
Subject: [PATCH] [libc++] Avoid including <string> in <mutex>
---
libcxx/include/CMakeLists.txt | 1 +
.../__condition_variable/condition_variable.h | 2 +-
libcxx/include/__mutex/unique_lock.h | 2 +-
libcxx/include/__system_error/system_error.h | 1 -
.../__system_error/throw_system_error.h | 25 +++++++++++++++++++
libcxx/include/__thread/thread.h | 5 +++-
libcxx/include/module.modulemap | 1 +
libcxx/include/print | 2 +-
libcxx/include/shared_mutex | 2 +-
libcxx/src/chrono.cpp | 2 +-
libcxx/src/filesystem/filesystem_clock.cpp | 1 +
libcxx/src/random.cpp | 2 +-
libcxx/src/system_error.cpp | 1 +
13 files changed, 39 insertions(+), 8 deletions(-)
create mode 100644 libcxx/include/__system_error/throw_system_error.h
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1610d1ee848a5f..9f5901cd471e73 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -716,6 +716,7 @@ set(files
__system_error/error_code.h
__system_error/error_condition.h
__system_error/system_error.h
+ __system_error/throw_system_error.h
__thread/formatter.h
__thread/id.h
__thread/jthread.h
diff --git a/libcxx/include/__condition_variable/condition_variable.h b/libcxx/include/__condition_variable/condition_variable.h
index 499e6f0f295dd3..4521fe274614ef 100644
--- a/libcxx/include/__condition_variable/condition_variable.h
+++ b/libcxx/include/__condition_variable/condition_variable.h
@@ -16,7 +16,7 @@
#include <__config>
#include <__mutex/mutex.h>
#include <__mutex/unique_lock.h>
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <__thread/support.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_floating_point.h>
diff --git a/libcxx/include/__mutex/unique_lock.h b/libcxx/include/__mutex/unique_lock.h
index c404921070f913..3642ab93cb1f7c 100644
--- a/libcxx/include/__mutex/unique_lock.h
+++ b/libcxx/include/__mutex/unique_lock.h
@@ -14,7 +14,7 @@
#include <__config>
#include <__memory/addressof.h>
#include <__mutex/tag_types.h>
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <__utility/swap.h>
#include <cerrno>
diff --git a/libcxx/include/__system_error/system_error.h b/libcxx/include/__system_error/system_error.h
index 2763aaba88f5fa..918effb6917cb4 100644
--- a/libcxx/include/__system_error/system_error.h
+++ b/libcxx/include/__system_error/system_error.h
@@ -39,7 +39,6 @@ class _LIBCPP_EXPORTED_FROM_ABI system_error : public runtime_error {
_LIBCPP_HIDE_FROM_ABI const error_code& code() const _NOEXCEPT { return __ec_; }
};
-[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI inline void __throw_system_error(error_code __ec, const char* __what_arg) {
#if _LIBCPP_HAS_EXCEPTIONS
throw system_error(__ec, __what_arg);
diff --git a/libcxx/include/__system_error/throw_system_error.h b/libcxx/include/__system_error/throw_system_error.h
new file mode 100644
index 00000000000000..e4605b6f014dc5
--- /dev/null
+++ b/libcxx/include/__system_error/throw_system_error.h
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
+#define _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
diff --git a/libcxx/include/__thread/thread.h b/libcxx/include/__thread/thread.h
index f417abc07b87c5..c40ffd25b903c2 100644
--- a/libcxx/include/__thread/thread.h
+++ b/libcxx/include/__thread/thread.h
@@ -18,10 +18,13 @@
#include <__functional/unary_function.h>
#include <__memory/unique_ptr.h>
#include <__mutex/mutex.h>
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <__thread/id.h>
#include <__thread/support.h>
#include <__type_traits/decay.h>
+#include <__type_traits/enable_if.h>
+#include <__type_traits/is_same.h>
+#include <__type_traits/remove_cvref.h>
#include <__utility/forward.h>
#include <tuple>
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index cd08b2810e437b..618261bd4eaa56 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1921,6 +1921,7 @@ module std [system] {
}
module error_condition { header "__system_error/error_condition.h" }
module system_error { header "__system_error/system_error.h" }
+ module throw_system_error { header "__system_error/throw_system_error.h" }
header "system_error"
export *
diff --git a/libcxx/include/print b/libcxx/include/print
index 7c808300701383..8a8b686d18f34d 100644
--- a/libcxx/include/print
+++ b/libcxx/include/print
@@ -36,7 +36,7 @@ namespace std {
#include <__assert>
#include <__concepts/same_as.h>
#include <__config>
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <__utility/forward.h>
#include <cerrno>
#include <cstdio>
diff --git a/libcxx/include/shared_mutex b/libcxx/include/shared_mutex
index 68030e9ce8ff4e..2552119405419c 100644
--- a/libcxx/include/shared_mutex
+++ b/libcxx/include/shared_mutex
@@ -134,7 +134,7 @@ template <class Mutex>
# include <__mutex/mutex.h>
# include <__mutex/tag_types.h>
# include <__mutex/unique_lock.h>
-# include <__system_error/system_error.h>
+# include <__system_error/throw_system_error.h>
# include <__utility/swap.h>
# include <cerrno>
# include <version>
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 098b6a171c8892..35105693b9f900 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -12,7 +12,7 @@
# define _LARGE_TIME_API
#endif
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <cerrno> // errno
#include <chrono>
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index e4cfb9e72845c6..d174ecdc9e1060 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include <__config>
+#include <__system_error/throw_system_error.h>
#include <chrono>
#include <filesystem>
#include <time.h>
diff --git a/libcxx/src/random.cpp b/libcxx/src/random.cpp
index 14c6f4473d70b9..3830e3918d2ee4 100644
--- a/libcxx/src/random.cpp
+++ b/libcxx/src/random.cpp
@@ -13,7 +13,7 @@
# define _CRT_RAND_S
#endif // defined(_LIBCPP_USING_WIN32_RANDOM)
-#include <__system_error/system_error.h>
+#include <__system_error/throw_system_error.h>
#include <limits>
#include <random>
diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp
index 53838c6c6d219b..d555bca995c454 100644
--- a/libcxx/src/system_error.cpp
+++ b/libcxx/src/system_error.cpp
@@ -8,6 +8,7 @@
#include <__assert>
#include <__config>
+#include <__system_error/throw_system_error.h>
#include <__verbose_abort>
#include <cerrno>
#include <cstdio>
More information about the libcxx-commits
mailing list