[libcxx-commits] [libcxx] 0ca4b9d - [libc++] Use the granular headers instead of <__locale> (#214029)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 5 03:01:41 PDT 2026
Author: Louis Dionne
Date: 2026-08-05T06:01:36-04:00
New Revision: 0ca4b9dd78f87ebf22a730cdf2de25860cb3d9d6
URL: https://github.com/llvm/llvm-project/commit/0ca4b9dd78f87ebf22a730cdf2de25860cb3d9d6
DIFF: https://github.com/llvm/llvm-project/commit/0ca4b9dd78f87ebf22a730cdf2de25860cb3d9d6.diff
LOG: [libc++] Use the granular headers instead of <__locale> (#214029)
After splitting up <__locale> into sub-headers, we can now use the
granular includes from the rest of the code and remove <__locale>.
Added:
Modified:
libcxx/include/CMakeLists.txt
libcxx/include/__filesystem/path.h
libcxx/include/__filesystem/u8path.h
libcxx/include/__format/format_context.h
libcxx/include/__format/format_functions.h
libcxx/include/__format/formatter_floating_point.h
libcxx/include/__format/formatter_integral.h
libcxx/include/__locale_dir/messages.h
libcxx/include/__locale_dir/money.h
libcxx/include/__locale_dir/num.h
libcxx/include/__locale_dir/time.h
libcxx/include/__locale_dir/wbuffer_convert.h
libcxx/include/__locale_dir/wstring_convert.h
libcxx/include/codecvt
libcxx/include/fstream
libcxx/include/ios
libcxx/include/locale
libcxx/include/module.modulemap.in
libcxx/include/regex
libcxx/include/sstream
libcxx/include/streambuf
libcxx/src/ios.cpp
libcxx/src/std_stream.h
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
libcxx/utils/generate_iwyu_mapping.py
Removed:
libcxx/include/__locale
################################################################################
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 7f47c51fb10ac..f5f07c24c8b1d 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -535,7 +535,6 @@ set(files
__iterator/static_bounded_iter.h
__iterator/unreachable_sentinel.h
__iterator/wrap_iter.h
- __locale
__locale_dir/check_grouping.h
__locale_dir/codecvt.h
__locale_dir/collate.h
diff --git a/libcxx/include/__filesystem/path.h b/libcxx/include/__filesystem/path.h
index 3e4e228017e14..14ba8c8e0fd29 100644
--- a/libcxx/include/__filesystem/path.h
+++ b/libcxx/include/__filesystem/path.h
@@ -29,8 +29,8 @@
#include <string_view>
#if _LIBCPP_HAS_LOCALIZATION
-# include <__locale> // for __narrow_to_utf8 and __widen_from_utf8
-# include <iomanip> // for quoted
+# include <__locale_dir/utf8_conversions.h>
+# include <iomanip> // for quoted
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__filesystem/u8path.h b/libcxx/include/__filesystem/u8path.h
index 77e7c0d6653da..213e9d5ac1e41 100644
--- a/libcxx/include/__filesystem/u8path.h
+++ b/libcxx/include/__filesystem/u8path.h
@@ -13,7 +13,7 @@
#include <__algorithm/unwrap_iter.h>
#include <__config>
#include <__filesystem/path.h>
-#include <__locale>
+#include <__locale_dir/utf8_conversions.h>
#include <string>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 6c21d792ef331..09a45cac28c57 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -26,7 +26,7 @@
#include <__variant/monostate.h>
#if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/locale.h>
# include <__optional/nullopt_t.h>
# include <__optional/optional.h>
#endif
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 8dfa0786c82b1..8f214a493a49e 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -44,7 +44,7 @@
#include <string_view>
#if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/locale.h>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__format/formatter_floating_point.h b/libcxx/include/__format/formatter_floating_point.h
index ea6d2b7f31783..a1ccf218e1397 100644
--- a/libcxx/include/__format/formatter_floating_point.h
+++ b/libcxx/include/__format/formatter_floating_point.h
@@ -41,7 +41,7 @@
#include <__utility/unreachable.h>
#if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/locale.h>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__format/formatter_integral.h b/libcxx/include/__format/formatter_integral.h
index 6e26ea7397d49..99a76c1efdd0d 100644
--- a/libcxx/include/__format/formatter_integral.h
+++ b/libcxx/include/__format/formatter_integral.h
@@ -34,7 +34,7 @@
#include <string_view>
#if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/locale.h>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
deleted file mode 100644
index c4b74aee4fb17..0000000000000
--- a/libcxx/include/__locale
+++ /dev/null
@@ -1,30 +0,0 @@
-// -*- 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___LOCALE
-#define _LIBCPP___LOCALE
-
-#include <__config>
-
-#if _LIBCPP_HAS_LOCALIZATION
-
-# include <__locale_dir/codecvt.h>
-# include <__locale_dir/collate.h>
-# include <__locale_dir/ctype.h>
-# include <__locale_dir/ctype_base.h>
-# include <__locale_dir/locale.h>
-# include <__locale_dir/utf8_conversions.h>
-
-# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-# endif
-
-#endif // _LIBCPP_HAS_LOCALIZATION
-
-#endif // _LIBCPP___LOCALE
diff --git a/libcxx/include/__locale_dir/messages.h b/libcxx/include/__locale_dir/messages.h
index 986a57d8b17b2..5408eb9936952 100644
--- a/libcxx/include/__locale_dir/messages.h
+++ b/libcxx/include/__locale_dir/messages.h
@@ -11,7 +11,8 @@
#include <__config>
#include <__iterator/back_insert_iterator.h>
-#include <__locale>
+#include <__locale_dir/locale.h>
+#include <__locale_dir/utf8_conversions.h>
#include <string>
#if _LIBCPP_HAS_LOCALIZATION
diff --git a/libcxx/include/__locale_dir/money.h b/libcxx/include/__locale_dir/money.h
index ba1cccb131f20..c39f31cc4f0da 100644
--- a/libcxx/include/__locale_dir/money.h
+++ b/libcxx/include/__locale_dir/money.h
@@ -14,9 +14,11 @@
#include <__algorithm/find.h>
#include <__algorithm/reverse.h>
#include <__config>
-#include <__locale>
#include <__locale_dir/check_grouping.h>
+#include <__locale_dir/ctype.h>
+#include <__locale_dir/ctype_base.h>
#include <__locale_dir/get_c_locale.h>
+#include <__locale_dir/locale.h>
#include <__locale_dir/pad_and_output.h>
#include <__memory/unique_ptr.h>
#include <ios>
diff --git a/libcxx/include/__locale_dir/num.h b/libcxx/include/__locale_dir/num.h
index 3c341c7779ab1..d5bc5e4695012 100644
--- a/libcxx/include/__locale_dir/num.h
+++ b/libcxx/include/__locale_dir/num.h
@@ -18,9 +18,10 @@
#include <__config>
#include <__iterator/istreambuf_iterator.h>
#include <__iterator/ostreambuf_iterator.h>
-#include <__locale>
#include <__locale_dir/check_grouping.h>
+#include <__locale_dir/ctype.h>
#include <__locale_dir/get_c_locale.h>
+#include <__locale_dir/locale.h>
#include <__locale_dir/pad_and_output.h>
#include <__locale_dir/scan_keyword.h>
#include <__memory/unique_ptr.h>
diff --git a/libcxx/include/__locale_dir/time.h b/libcxx/include/__locale_dir/time.h
index 4c082e0e40944..34adb52d2e3bc 100644
--- a/libcxx/include/__locale_dir/time.h
+++ b/libcxx/include/__locale_dir/time.h
@@ -11,8 +11,10 @@
#include <__algorithm/copy.h>
#include <__config>
-#include <__locale>
+#include <__locale_dir/ctype.h>
+#include <__locale_dir/ctype_base.h>
#include <__locale_dir/get_c_locale.h>
+#include <__locale_dir/locale.h>
#include <__locale_dir/scan_keyword.h>
#include <ios>
diff --git a/libcxx/include/__locale_dir/wbuffer_convert.h b/libcxx/include/__locale_dir/wbuffer_convert.h
index 08df30a1183f0..49bf74cc58863 100644
--- a/libcxx/include/__locale_dir/wbuffer_convert.h
+++ b/libcxx/include/__locale_dir/wbuffer_convert.h
@@ -11,7 +11,7 @@
#include <__algorithm/reverse.h>
#include <__config>
-#include <__locale>
+#include <__locale_dir/codecvt.h>
#include <__string/char_traits.h>
#include <ios>
#include <streambuf>
diff --git a/libcxx/include/__locale_dir/wstring_convert.h b/libcxx/include/__locale_dir/wstring_convert.h
index 05b81e0a880ed..b3393479037f7 100644
--- a/libcxx/include/__locale_dir/wstring_convert.h
+++ b/libcxx/include/__locale_dir/wstring_convert.h
@@ -10,7 +10,7 @@
#define _LIBCPP___LOCALE_DIR_WSTRING_CONVERT_H
#include <__config>
-#include <__locale>
+#include <__locale_dir/codecvt.h>
#include <__memory/allocator.h>
#include <string>
diff --git a/libcxx/include/codecvt b/libcxx/include/codecvt
index 6c3ac727e3f7f..b2ae0e869136f 100644
--- a/libcxx/include/codecvt
+++ b/libcxx/include/codecvt
@@ -61,7 +61,7 @@ class codecvt_utf8_utf16
# if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/codecvt.h>
# include <version>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index eb208a4692806..0023191166c3b 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -197,7 +197,8 @@ typedef basic_fstream<wchar_t> wfstream;
# include <__assert>
# include <__filesystem/path.h>
# include <__fwd/fstream.h>
-# include <__locale>
+# include <__locale_dir/codecvt.h>
+# include <__locale_dir/locale.h>
# include <__memory/addressof.h>
# include <__memory/unique_ptr.h>
# include <__ostream/basic_ostream.h>
diff --git a/libcxx/include/ios b/libcxx/include/ios
index 04abd3bd1935f..8173803c2f129 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -225,7 +225,8 @@ storage-class-specifier const error_category& iostream_category() noexcept;
# include <__fwd/ios.h>
# include <__ios/fpos.h>
-# include <__locale>
+# include <__locale_dir/ctype.h>
+# include <__locale_dir/locale.h>
# include <__memory/addressof.h>
# include <__system_error/error_category.h>
# include <__system_error/error_code.h>
diff --git a/libcxx/include/locale b/libcxx/include/locale
index 369dec42c92f7..bfffc1886269d 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -194,7 +194,11 @@ template <class charT> class messages_byname;
# if _LIBCPP_HAS_LOCALIZATION
-# include <__locale>
+# include <__locale_dir/codecvt.h>
+# include <__locale_dir/collate.h>
+# include <__locale_dir/ctype.h>
+# include <__locale_dir/ctype_base.h>
+# include <__locale_dir/locale.h>
# include <__locale_dir/messages.h>
# include <__locale_dir/money.h>
# include <__locale_dir/num.h>
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index a15b2dd08f634..97467ca5757e4 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1642,7 +1642,6 @@ module std {
// which are in turn used by the facet headers that make up std.locale, so making them part
// of std.locale would create a cycle.
module locale_base {
- header "__locale"
module codecvt { header "__locale_dir/codecvt.h" export * }
module collate { header "__locale_dir/collate.h" export * }
module ctype { header "__locale_dir/ctype.h" export * }
diff --git a/libcxx/include/regex b/libcxx/include/regex
index ce908f651e49b..a11635093ec2b 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -815,7 +815,10 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
# include <__iterator/back_insert_iterator.h>
# include <__iterator/default_sentinel.h>
# include <__iterator/wrap_iter.h>
-# include <__locale>
+# include <__locale_dir/collate.h>
+# include <__locale_dir/ctype.h>
+# include <__locale_dir/ctype_base.h>
+# include <__locale_dir/locale.h>
# include <__memory/addressof.h>
# include <__memory/pointer_traits.h>
# include <__memory/shared_ptr.h>
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index f77a0c0dd3677..faf203778753c 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -320,7 +320,7 @@ typedef basic_stringstream<wchar_t> wstringstream;
# if _LIBCPP_HAS_LOCALIZATION
# include <__fwd/sstream.h>
-# include <__locale>
+# include <__locale_dir/locale.h>
# include <__ostream/basic_ostream.h>
# include <__type_traits/is_convertible.h>
# include <__utility/swap.h>
diff --git a/libcxx/include/streambuf b/libcxx/include/streambuf
index 2b1d5bd868d47..9f563fa547e4d 100644
--- a/libcxx/include/streambuf
+++ b/libcxx/include/streambuf
@@ -116,7 +116,7 @@ protected:
# include <__assert>
# include <__fwd/streambuf.h>
-# include <__locale>
+# include <__locale_dir/locale.h>
# include <__memory/valid_range.h>
# include <__type_traits/is_same.h>
# include <__utility/scope_guard.h>
diff --git a/libcxx/src/ios.cpp b/libcxx/src/ios.cpp
index 3d4e7eb4436fd..019bd9cea9bd4 100644
--- a/libcxx/src/ios.cpp
+++ b/libcxx/src/ios.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include <__config>
-#include <__locale>
+#include <__locale_dir/locale.h>
#include <algorithm>
#include <atomic>
#include <ios>
diff --git a/libcxx/src/std_stream.h b/libcxx/src/std_stream.h
index 32f23e78d4e69..6aa15fd88775e 100644
--- a/libcxx/src/std_stream.h
+++ b/libcxx/src/std_stream.h
@@ -11,7 +11,8 @@
#define _LIBCPP_STD_STREAM_H
#include <__config>
-#include <__locale>
+#include <__locale_dir/codecvt.h>
+#include <__locale_dir/locale.h>
#include <cstdio>
#include <istream>
#include <ostream>
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp
index ec4c8a009ba0c..e26fbac9a86ae 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp
@@ -18,6 +18,7 @@
// RUN:
diff %t.expected %t.actual
#include <iostream>
+#include <locale>
struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
using base = std::codecvt<wchar_t, char, std::mbstate_t>;
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
index 6ae1972234b2b..64172064bea70 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
@@ -22,6 +22,7 @@
#include <iostream>
#include <cassert>
+#include <locale>
struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
using base = std::codecvt<wchar_t, char, std::mbstate_t>;
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
index 87fc167a20b31..c575332f34714 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
@@ -18,6 +18,7 @@
// RUN:
diff %t.expected %t.actual
#include <iostream>
+#include <locale>
struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
using base = std::codecvt<wchar_t, char, std::mbstate_t>;
diff --git a/libcxx/utils/generate_iwyu_mapping.py b/libcxx/utils/generate_iwyu_mapping.py
index 35da70f62f264..d041cbcdd13d4 100644
--- a/libcxx/utils/generate_iwyu_mapping.py
+++ b/libcxx/utils/generate_iwyu_mapping.py
@@ -27,8 +27,6 @@ def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
return ["version"]
elif header == "__hash_table":
return ["unordered_map", "unordered_set"]
- elif header == "__locale":
- return ["locale"]
elif re.match("__locale_dir/.+", header):
return ["locale"]
elif re.match("__math/.+", header):
More information about the libcxx-commits
mailing list