Skip to content

Commit dcc378e

Browse files
ldionnetstellar
authored andcommitted
[libc++] Guard <codecvt> contents on _LIBCPP_HAS_LOCALIZATION (llvm#129112)
The codecvt class is defined in <locale> and the contents of the <codecvt> header don't work when localization is disabled. Without this guard, builds with localization disabled that happen to include <codecvt> could be broken because they would try to include <__locale>, which ends up trying to include the locale base API and eventually platform headers like <xlocale.h> that may not exist. (cherry picked from commit fda7373)
1 parent 0f5e7e8 commit dcc378e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

libcxx/include/codecvt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ class codecvt_utf8_utf16
5858
# include <__cxx03/codecvt>
5959
#else
6060
# include <__config>
61-
# include <__locale>
62-
# include <version>
6361

64-
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65-
# pragma GCC system_header
66-
# endif
62+
# if _LIBCPP_HAS_LOCALIZATION
63+
64+
# include <__locale>
65+
# include <version>
6766

68-
# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
67+
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68+
# pragma GCC system_header
69+
# endif
70+
71+
# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
6972

7073
_LIBCPP_BEGIN_NAMESPACE_STD
7174

@@ -76,7 +79,7 @@ enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode { consume_header = 4, generate_hea
7679
template <class _Elem>
7780
class __codecvt_utf8;
7881

79-
# if _LIBCPP_HAS_WIDE_CHARACTERS
82+
# if _LIBCPP_HAS_WIDE_CHARACTERS
8083
template <>
8184
class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
8285
unsigned long __maxcode_;
@@ -115,7 +118,7 @@ protected:
115118
int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
116119
int do_max_length() const _NOEXCEPT override;
117120
};
118-
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
121+
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
119122

120123
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
121124
template <>
@@ -206,7 +209,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
206209
template <class _Elem, bool _LittleEndian>
207210
class __codecvt_utf16;
208211

209-
# if _LIBCPP_HAS_WIDE_CHARACTERS
212+
# if _LIBCPP_HAS_WIDE_CHARACTERS
210213
template <>
211214
class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, false> : public codecvt<wchar_t, char, mbstate_t> {
212215
unsigned long __maxcode_;
@@ -284,7 +287,7 @@ protected:
284287
int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
285288
int do_max_length() const _NOEXCEPT override;
286289
};
287-
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
290+
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
288291

289292
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
290293
template <>
@@ -451,7 +454,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
451454
template <class _Elem>
452455
class __codecvt_utf8_utf16;
453456

454-
# if _LIBCPP_HAS_WIDE_CHARACTERS
457+
# if _LIBCPP_HAS_WIDE_CHARACTERS
455458
template <>
456459
class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
457460
unsigned long __maxcode_;
@@ -490,7 +493,7 @@ protected:
490493
int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
491494
int do_max_length() const _NOEXCEPT override;
492495
};
493-
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
496+
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
494497

495498
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
496499
template <>
@@ -579,7 +582,9 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
579582

580583
_LIBCPP_END_NAMESPACE_STD
581584

582-
# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
585+
# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
586+
587+
# endif // _LIBCPP_HAS_LOCALIZATION
583588

584589
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
585590
# include <atomic>

0 commit comments

Comments
 (0)