[libcxx-commits] [libcxx] [libc++] Use std::to_string to format thread::id (PR #181624)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 16 02:40:56 PST 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/181624

This avoids including `<sstream>`.


>From 3ac5c23bd3f291d0857e6943050b0c1169e0c133 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 16 Feb 2026 11:40:25 +0100
Subject: [PATCH] [libc++] Use std::to_string to format thread::id

---
 libcxx/include/__thread/thread.h                 |  9 +--------
 libcxx/include/future                            |  5 +++++
 libcxx/include/thread                            |  5 +++++
 libcxx/test/libcxx/transitive_includes/cxx26.csv | 10 ----------
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/libcxx/include/__thread/thread.h b/libcxx/include/__thread/thread.h
index b2f51aa816c10..bd79dadc5eee6 100644
--- a/libcxx/include/__thread/thread.h
+++ b/libcxx/include/__thread/thread.h
@@ -32,10 +32,6 @@
 #include <__utility/forward.h>
 #include <tuple>
 
-#if _LIBCPP_HAS_LOCALIZATION
-#  include <sstream>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -147,10 +143,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
   // use a temporary stream instead and just output the thread
   // id representation as a string.
 
-  basic_ostringstream<_CharT, _Traits> __sstr;
-  __sstr.imbue(locale::classic());
-  __sstr << __id.__id_;
-  return __os << __sstr.str();
+  return __os << std::to_string(__id.__id_);
 }
 #  endif // _LIBCPP_HAS_LOCALIZATION
 
diff --git a/libcxx/include/future b/libcxx/include/future
index 4084148e52af6..a99a7ae486490 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -2075,6 +2075,11 @@ _LIBCPP_POP_MACROS
 #    include <system_error>
 #    include <thread>
 #  endif
+
+#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
+#    include <sstream>
+#  endif
+
 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
 
 #endif // _LIBCPP_FUTURE
diff --git a/libcxx/include/thread b/libcxx/include/thread
index 029ed418e2070..e14e47d02788b 100644
--- a/libcxx/include/thread
+++ b/libcxx/include/thread
@@ -128,6 +128,11 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 #    include <system_error>
 #    include <type_traits>
 #  endif
+
+#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
+#    include <sstream>
+#  endif
+
 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
 
 #endif // _LIBCPP_THREAD
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index c11fb5ac10016..8016de1138091 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -425,7 +425,6 @@ functional tuple
 functional typeinfo
 functional unordered_map
 functional version
-future bitset
 future cctype
 future cerrno
 future climits
@@ -440,14 +439,10 @@ future ctime
 future cwchar
 future cwctype
 future initializer_list
-future ios
 future iosfwd
-future istream
 future limits
 future ratio
-future sstream
 future stdexcept
-future streambuf
 future string
 future string_view
 future tuple
@@ -1050,7 +1045,6 @@ system_error tuple
 system_error version
 thread array
 thread atomic
-thread bitset
 thread cctype
 thread cerrno
 thread climits
@@ -1065,14 +1059,10 @@ thread ctime
 thread cwchar
 thread cwctype
 thread initializer_list
-thread ios
 thread iosfwd
-thread istream
 thread limits
 thread ratio
-thread sstream
 thread stdexcept
-thread streambuf
 thread string
 thread string_view
 thread tuple



More information about the libcxx-commits mailing list