2323// Variadic functions may be implemented as templates with a parameter pack instead
2424// of C-style variadic functions.
2525//
26+ // Most of these functions are only required when building the library. Functions that are also
27+ // required when merely using the headers are marked as such below.
28+ //
2629// TODO: __localeconv shouldn't take a reference, but the Windows implementation doesn't allow copying __locale_t
30+ // TODO: Eliminate the need for any of these functions from the headers.
2731//
2832// Locale management
2933// -----------------
3034// namespace __locale {
31- // using __locale_t = implementation-defined;
35+ // using __locale_t = implementation-defined; // required by the headers
3236// using __lconv_t = implementation-defined;
3337// __locale_t __newlocale(int, const char*, __locale_t);
3438// void __freelocale(__locale_t);
3539// char* __setlocale(int, const char*);
3640// __lconv_t* __localeconv(__locale_t&);
3741// }
3842//
43+ // // required by the headers
3944// #define _LIBCPP_COLLATE_MASK /* implementation-defined */
4045// #define _LIBCPP_CTYPE_MASK /* implementation-defined */
4146// #define _LIBCPP_MONETARY_MASK /* implementation-defined */
4853// Strtonum functions
4954// ------------------
5055// namespace __locale {
56+ // // required by the headers
5157// float __strtof(const char*, char**, __locale_t);
5258// double __strtod(const char*, char**, __locale_t);
5359// long double __strtold(const char*, char**, __locale_t);
6066// namespace __locale {
6167// int __islower(int, __locale_t);
6268// int __isupper(int, __locale_t);
63- // int __isdigit(int, __locale_t);
64- // int __isxdigit(int, __locale_t);
69+ // int __isdigit(int, __locale_t); // required by the headers
70+ // int __isxdigit(int, __locale_t); // required by the headers
6571// int __toupper(int, __locale_t);
6672// int __tolower(int, __locale_t);
6773// int __strcoll(const char*, const char*, __locale_t);
99105// int __mbtowc(wchar_t*, const char*, size_t, __locale_t);
100106// size_t __mbrlen(const char*, size_t, mbstate_t*, __locale_t);
101107// size_t __mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*, __locale_t);
102- // int __snprintf(char*, size_t, __locale_t, const char*, ...);
103- // int __asprintf(char**, __locale_t, const char*, ...);
104- // int __sscanf(const char*, __locale_t, const char*, ...);
108+ //
109+ // int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
110+ // int __asprintf(char**, __locale_t, const char*, ...); // required by the headers
111+ // int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers
105112// }
106113
107114#if defined(__APPLE__)
@@ -143,8 +150,19 @@ namespace __locale {
143150//
144151// Locale management
145152//
153+ # define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
154+ # define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
155+ # define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
156+ # define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
157+ # define _LIBCPP_TIME_MASK LC_TIME_MASK
158+ # define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
159+ # define _LIBCPP_ALL_MASK LC_ALL_MASK
160+ # define _LIBCPP_LC_ALL LC_ALL
161+
146162using __locale_t _LIBCPP_NODEBUG = locale_t ;
147- using __lconv_t _LIBCPP_NODEBUG = lconv;
163+
164+ # if defined(_LIBCPP_BUILDING_LIBRARY)
165+ using __lconv_t _LIBCPP_NODEBUG = lconv;
148166
149167inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale (int __category_mask, const char * __name, __locale_t __loc) {
150168 return newlocale (__category_mask, __name, __loc);
@@ -157,15 +175,7 @@ inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __loc
157175inline _LIBCPP_HIDE_FROM_ABI void __freelocale (__locale_t __loc) { freelocale (__loc); }
158176
159177inline _LIBCPP_HIDE_FROM_ABI __lconv_t * __localeconv (__locale_t & __loc) { return __libcpp_localeconv_l (__loc); }
160-
161- # define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
162- # define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
163- # define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
164- # define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
165- # define _LIBCPP_TIME_MASK LC_TIME_MASK
166- # define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
167- # define _LIBCPP_ALL_MASK LC_ALL_MASK
168- # define _LIBCPP_LC_ALL LC_ALL
178+ # endif // _LIBCPP_BUILDING_LIBRARY
169179
170180//
171181// Strtonum functions
@@ -194,10 +204,15 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
194204//
195205// Character manipulation functions
196206//
207+ # if defined(_LIBCPP_BUILDING_LIBRARY)
197208inline _LIBCPP_HIDE_FROM_ABI int __islower (int __ch, __locale_t __loc) { return islower_l (__ch, __loc); }
198209inline _LIBCPP_HIDE_FROM_ABI int __isupper (int __ch, __locale_t __loc) { return isupper_l (__ch, __loc); }
210+ # endif
211+
199212inline _LIBCPP_HIDE_FROM_ABI int __isdigit (int __ch, __locale_t __loc) { return isdigit_l (__ch, __loc); }
200213inline _LIBCPP_HIDE_FROM_ABI int __isxdigit (int __ch, __locale_t __loc) { return isxdigit_l (__ch, __loc); }
214+
215+ # if defined(_LIBCPP_BUILDING_LIBRARY)
201216inline _LIBCPP_HIDE_FROM_ABI int __strcoll (const char * __s1, const char * __s2, __locale_t __loc) {
202217 return strcoll_l (__s1, __s2, __loc);
203218}
@@ -207,7 +222,7 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
207222inline _LIBCPP_HIDE_FROM_ABI int __toupper (int __ch, __locale_t __loc) { return toupper_l (__ch, __loc); }
208223inline _LIBCPP_HIDE_FROM_ABI int __tolower (int __ch, __locale_t __loc) { return tolower_l (__ch, __loc); }
209224
210- # if _LIBCPP_HAS_WIDE_CHARACTERS
225+ # if _LIBCPP_HAS_WIDE_CHARACTERS
211226inline _LIBCPP_HIDE_FROM_ABI int __wcscoll (const wchar_t * __s1, const wchar_t * __s2, __locale_t __loc) {
212227 return wcscoll_l (__s1, __s2, __loc);
213228}
@@ -229,7 +244,7 @@ inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { ret
229244inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit (wint_t __ch, __locale_t __loc) { return iswxdigit_l (__ch, __loc); }
230245inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper (wint_t __ch, __locale_t __loc) { return towupper_l (__ch, __loc); }
231246inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower (wint_t __ch, __locale_t __loc) { return towlower_l (__ch, __loc); }
232- # endif
247+ # endif
233248
234249inline _LIBCPP_HIDE_FROM_ABI size_t
235250__strftime (char * __s, size_t __max, const char * __format, const tm* __tm, __locale_t __loc) {
@@ -242,7 +257,7 @@ __strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __loca
242257inline _LIBCPP_HIDE_FROM_ABI decltype (__libcpp_mb_cur_max_l(__locale_t ())) __mb_len_max(__locale_t __loc) {
243258 return __libcpp_mb_cur_max_l (__loc);
244259}
245- # if _LIBCPP_HAS_WIDE_CHARACTERS
260+ # if _LIBCPP_HAS_WIDE_CHARACTERS
246261inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc (int __ch, __locale_t __loc) { return __libcpp_btowc_l (__ch, __loc); }
247262inline _LIBCPP_HIDE_FROM_ABI int __wctob (wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l (__ch, __loc); }
248263inline _LIBCPP_HIDE_FROM_ABI size_t
@@ -270,7 +285,8 @@ inline _LIBCPP_HIDE_FROM_ABI size_t
270285__mbsrtowcs (wchar_t * __dest, const char ** __src, size_t __len, mbstate_t * __ps, __locale_t __loc) {
271286 return __libcpp_mbsrtowcs_l (__dest, __src, __len, __ps, __loc);
272287}
273- # endif
288+ # endif // _LIBCPP_HAS_WIDE_CHARACTERS
289+ # endif // _LIBCPP_BUILDING_LIBRARY
274290
275291_LIBCPP_DIAGNOSTIC_PUSH
276292_LIBCPP_CLANG_DIAGNOSTIC_IGNORED (" -Wgcc-compat" )
0 commit comments