Skip to content

[libc++] Disable isw*_l functions on old MSVCRT (< 0x800) #144273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hpoussin
Copy link
Contributor

This fixes linking on platforms older than Windows 10, which don't have these functions.

In that case, implement char functions with specific locale by calling the same function without locale (which will use the ambiant one).

This fixes linking on platforms older than Windows 10, which don't
have these functions.

In that case, implement char functions with specific locale by calling
the same function without locale (which will use the ambiant one).
@hpoussin hpoussin requested a review from a team as a code owner June 15, 2025 18:50
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 15, 2025

@llvm/pr-subscribers-libcxx

Author: Hervé Poussineau (hpoussin)

Changes

This fixes linking on platforms older than Windows 10, which don't have these functions.

In that case, implement char functions with specific locale by calling the same function without locale (which will use the ambiant one).


Full diff: https://github.com/llvm/llvm-project/pull/144273.diff

3 Files Affected:

  • (modified) libcxx/include/__cxx03/__config (+3-1)
  • (modified) libcxx/include/__locale_dir/support/windows.h (+19-1)
  • (modified) libcxx/src/support/win32/locale_win32.cpp (+62)
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index ef47327d96355..0839d19ad5ab4 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -595,7 +595,9 @@ typedef __char32_t char32_t;
 // clang-format on
 
 #  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
-#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
+#    if !defined(__MSVCRT_VERSION__) || __MSVCRT_VERSION__ >= 0x800
+#      define _LIBCPP_LOCALE__L_EXTENSIONS 1
+#    endif
 #  endif
 
 #  ifdef __FreeBSD__
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index 0d3089c150081..6a2ffd897bb7a 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -221,6 +221,23 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
 }
 
 #  if _LIBCPP_HAS_WIDE_CHARACTERS
+#    if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
+_LIBCPP_EXPORTED_FROM_ABI int __iswctype(wint_t c, wctype_t __type, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswspace(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswprint(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswcntrl(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswupper(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswlower(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswalpha(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswblank(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswdigit(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswpunct(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswxdigit(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI wint_t __towupper(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI wint_t __towlower(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc);
+#    else
 inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
   return ::_iswctype_l(__c, __type, __loc);
 }
@@ -245,7 +262,8 @@ inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t*
 inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
   return ::_wcsxfrm_l(__dest, __src, __n, __loc);
 }
-#  endif // _LIBCPP_HAS_WIDE_CHARACTERS
+#    endif // defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
+#  endif   // _LIBCPP_HAS_WIDE_CHARACTERS
 
 #  if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
 _LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t);
diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp
index 24402e818d95d..f8a963faa572f 100644
--- a/libcxx/src/support/win32/locale_win32.cpp
+++ b/libcxx/src/support/win32/locale_win32.cpp
@@ -57,6 +57,68 @@ size_t __strftime(char* ret, size_t n, const char* format, const struct tm* tm,
   __locale_guard __current(loc);
   return std::strftime(ret, n, format, tm);
 }
+#  if _LIBCPP_HAS_WIDE_CHARACTERS
+int __iswctype(wint_t c, wctype_t type, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswctype(c, type);
+}
+int __iswspace(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswspace(c);
+}
+int __iswprint(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswprint(c);
+}
+int __iswcntrl(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswcntrl(c);
+}
+int __iswupper(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswupper(c);
+}
+int __iswlower(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswlower(c);
+}
+int __iswalpha(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswalpha(c);
+}
+int __iswblank(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswblank(c);
+}
+int __iswdigit(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswdigit(c);
+}
+int __iswpunct(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswpunct(c);
+}
+int __iswxdigit(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::iswxdigit(c);
+}
+wint_t __towupper(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::towupper(c);
+}
+wint_t __towlower(wint_t c, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::towlower(c);
+}
+int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::wcscoll(ws1, ws2);
+}
+size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc) {
+  __locale_guard __current(loc);
+  return ::wcsxfrm(dest, src, n);
+}
+#  endif
 #endif
 
 //

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants