[libcxx-commits] [libcxx] [libcxx][locale] Refactor strtonum functions using __str_to_float_c_locale<FloatT> (PR #222081)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 21 05:27:17 PDT 2026


https://github.com/Himadhith updated https://github.com/llvm/llvm-project/pull/222081

>From c5ab0d0a0091260299a1cb1c03485d9376cf7863 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Tue, 8 Sep 2026 22:51:57 +0530
Subject: [PATCH 1/3] [libcxx][locale] Refactor strtonum functions using
 __str_to_float_c_locale<FloatT>

---
 libcxx/include/__locale_dir/locale_base_api.h | 20 ++++++---
 libcxx/include/__locale_dir/num.h             |  6 +--
 libcxx/include/__locale_dir/support/aix.h     | 44 +++++++------------
 .../include/__locale_dir/support/bsd_like.h   | 12 +++--
 libcxx/include/__locale_dir/support/linux.h   | 12 +++--
 libcxx/include/__locale_dir/support/newlib.h  | 12 +++--
 .../__locale_dir/support/no_locale/strtonum.h | 12 +++--
 libcxx/include/__locale_dir/support/openbsd.h | 21 +++++++--
 libcxx/include/__locale_dir/support/windows.h | 25 ++++++++---
 libcxx/src/support/win32/locale_win32.cpp     |  6 ++-
 10 files changed, 110 insertions(+), 60 deletions(-)

diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 14ff9d8a45b565..92ff3abbfc2408 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -54,9 +54,8 @@
 // ------------------
 // namespace __locale {
 //  // required by the headers
-//  float               __strtof(const char*, char**, __locale_t);
-//  double              __strtod(const char*, char**, __locale_t);
-//  long double         __strtold(const char*, char**, __locale_t);
+//  template <class FloatT>
+//  FloatT __str_to_float_c_locale(const char*, char**, __locale_t);
 // }
 //
 // Character manipulation functions
@@ -185,15 +184,24 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return strtof_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return strtod_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/num.h b/libcxx/include/__locale_dir/num.h
index e924c88d0955c9..8cc0b544f25b08 100644
--- a/libcxx/include/__locale_dir/num.h
+++ b/libcxx/include/__locale_dir/num.h
@@ -306,17 +306,17 @@ _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
-  return __locale::__strtof(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<float>(__a, __p2,  __locale::__get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
-  return __locale::__strtod(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<double>(__a, __p2,  __locale::__get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
-  return __locale::__strtold(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<long double>(__a, __p2,  __locale::__get_c_locale());
 }
 
 template <class _Tp>
diff --git a/libcxx/include/__locale_dir/support/aix.h b/libcxx/include/__locale_dir/support/aix.h
index d5c2b395b1a37e..15de092b9cc6e4 100644
--- a/libcxx/include/__locale_dir/support/aix.h
+++ b/libcxx/include/__locale_dir/support/aix.h
@@ -86,44 +86,30 @@ inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc)
 }
 #endif // _LIBCPP_BUILDING_LIBRARY
 
-// The following structure is a quick-and-dirty workaround for routines that AIX
-// does not provide in the "_l" (locale-aware) variants.
-struct __setAndRestore {
-  explicit __setAndRestore(locale_t locale) {
-    if (locale == (locale_t)0) {
-      __cloc   = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0);
-      __stored = uselocale(__cloc);
-    } else {
-      __stored = uselocale(locale);
-    }
-  }
-
-  ~__setAndRestore() {
-    uselocale(__stored);
-    if (__cloc)
-      freelocale(__cloc);
-  }
-
-private:
-  locale_t __stored = (locale_t)0;
-  locale_t __cloc   = (locale_t)0;
-};
-
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __setAndRestore __newloc(__loc);
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
+  __locale_guard __current(__loc);
   return ::strtof(__nptr, __endptr);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __setAndRestore __newloc(__loc);
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+  __locale_guard __current(__loc);
   return ::strtod(__nptr, __endptr);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __setAndRestore __newloc(__loc);
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+  __locale_guard __current(__loc);
   return ::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index ebe3f726e34ffc..1164fcc454d0a2 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -78,15 +78,21 @@ inline __locale_t __get_c_locale() {
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 8d20bbe9180c4f..48e5200c9f3ee2 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -85,15 +85,21 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/newlib.h b/libcxx/include/__locale_dir/support/newlib.h
index daf60e8a48ea26..87297401fce885 100644
--- a/libcxx/include/__locale_dir/support/newlib.h
+++ b/libcxx/include/__locale_dir/support/newlib.h
@@ -86,15 +86,21 @@ inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc)
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+
+template<>
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+template<>
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+template<>
+inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/no_locale/strtonum.h b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
index 59544e10e4a4c0..af7801bf6ca0b8 100644
--- a/libcxx/include/__locale_dir/support/no_locale/strtonum.h
+++ b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
@@ -22,15 +22,21 @@ namespace __locale {
 //
 // Strtonum functions
 //
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t) {
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t);
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
   return std::strtof(__nptr, __endptr);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
   return std::strtod(__nptr, __endptr);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
   return std::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/openbsd.h b/libcxx/include/__locale_dir/support/openbsd.h
index 85f008f8a17f07..cd4d0d3d657cfa 100644
--- a/libcxx/include/__locale_dir/support/openbsd.h
+++ b/libcxx/include/__locale_dir/support/openbsd.h
@@ -79,11 +79,26 @@ inline __lconv_t* __localeconv(__locale_t& __loc) {
 //
 // Strtonum functions
 //
-inline float __strtof(const char* __nptr, char** __endptr, __locale_t) { return ::strtof(__nptr, __endptr); }
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t);
 
-inline double __strtod(const char* __nptr, char** __endptr, __locale_t) { return ::strtod(__nptr, __endptr); }
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
+  return ::strtof(__nptr, __endptr);
+}
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
+  return ::strtod(__nptr, __endptr);
+}
 
-inline long double __strtold(const char* __nptr, char** __endptr, __locale_t) { return ::strtold(__nptr, __endptr); }
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
+  return ::strtold(__nptr, __endptr);
+}
 
 //
 // Character manipulation functions
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index 5f35d089ac1fcf..e151709e65d03c 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -172,19 +172,34 @@ _LIBCPP_EXPORTED_FROM_ABI const char* __get_locale_encoding(__locale_t __loc);
 //
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
+template <class _FloatT>
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
 #if defined(_LIBCPP_MSVCRT)
-inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::_strtof_l(__nptr, __endptr, __loc);
 }
-inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::_strtold_l(__nptr, __endptr, __loc);
 }
 #else
-_LIBCPP_EXPORTED_FROM_ABI float __strtof(const char*, char**, __locale_t);
-_LIBCPP_EXPORTED_FROM_ABI long double __strtold(const char*, char**, __locale_t);
+template <>
+_LIBCPP_EXPORTED_FROM_ABI float
+__str_to_float_c_locale<float>(const char*, char**, __locale_t);
+
+template <>
+_LIBCPP_EXPORTED_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char*, char**, __locale_t);
 #endif
 
-inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::_strtod_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp
index c5117564438a5c..e9660d06ed9200 100644
--- a/libcxx/src/support/win32/locale_win32.cpp
+++ b/libcxx/src/support/win32/locale_win32.cpp
@@ -299,12 +299,14 @@ const char* __get_locale_encoding(__locale_t loc) {
 // Strtonum functions
 //
 #if !defined(_LIBCPP_MSVCRT)
-float __strtof(const char* nptr, char** endptr, __locale_t loc) {
+template <>
+float __locale::__str_to_float_c_locale<float>(const char* nptr, char** endptr, __locale_t loc) {
   __locale_guard __current(loc);
   return std::strtof(nptr, endptr);
 }
 
-long double __strtold(const char* nptr, char** endptr, __locale_t loc) {
+template <>
+long double __locale::__str_to_float_c_locale<long double>(const char* nptr, char** endptr, __locale_t loc) {
   __locale_guard __current(loc);
   return std::strtold(nptr, endptr);
 }

>From c4c2755412a90b7f9c3d18ec28572072f3743ba3 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Tue, 8 Sep 2026 14:05:47 -0400
Subject: [PATCH 2/3] fix format

---
 libcxx/include/__locale_dir/num.h                 |  6 +++---
 libcxx/include/__locale_dir/support/bsd_like.h    |  9 ++++++---
 libcxx/include/__locale_dir/support/linux.h       |  9 ++++++---
 libcxx/include/__locale_dir/support/newlib.h      | 15 +++++++++------
 .../__locale_dir/support/no_locale/strtonum.h     |  3 ++-
 libcxx/include/__locale_dir/support/openbsd.h     |  6 ++----
 libcxx/include/__locale_dir/support/windows.h     | 10 ++++------
 7 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/libcxx/include/__locale_dir/num.h b/libcxx/include/__locale_dir/num.h
index 8cc0b544f25b08..6395c6b6417dd5 100644
--- a/libcxx/include/__locale_dir/num.h
+++ b/libcxx/include/__locale_dir/num.h
@@ -306,17 +306,17 @@ _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<float>(__a, __p2,  __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<float>(__a, __p2, __locale::__get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<double>(__a, __p2,  __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<double>(__a, __p2, __locale::__get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<long double>(__a, __p2,  __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<long double>(__a, __p2, __locale::__get_c_locale());
 }
 
 template <class _Tp>
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index 1164fcc454d0a2..070f3dc3ad6ec0 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -82,17 +82,20 @@ template <class _FloatT>
 _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 48e5200c9f3ee2..307cbf75fcfe02 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -89,17 +89,20 @@ template <class _FloatT>
 _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/newlib.h b/libcxx/include/__locale_dir/support/newlib.h
index 87297401fce885..d64e1f0721c23a 100644
--- a/libcxx/include/__locale_dir/support/newlib.h
+++ b/libcxx/include/__locale_dir/support/newlib.h
@@ -89,18 +89,21 @@ inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc)
 template <class _FloatT>
 _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
 
-template<>
-inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI float
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtof_l(__nptr, __endptr, __loc);
 }
 
-template<>
-inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI double
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtod_l(__nptr, __endptr, __loc);
 }
 
-template<>
-inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
+template <>
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::strtold_l(__nptr, __endptr, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/no_locale/strtonum.h b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
index af7801bf6ca0b8..699eb3e6fa1736 100644
--- a/libcxx/include/__locale_dir/support/no_locale/strtonum.h
+++ b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
@@ -36,7 +36,8 @@ inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char*
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI long double __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI long double
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
   return std::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/openbsd.h b/libcxx/include/__locale_dir/support/openbsd.h
index cd4d0d3d657cfa..8d3afe7c846daa 100644
--- a/libcxx/include/__locale_dir/support/openbsd.h
+++ b/libcxx/include/__locale_dir/support/openbsd.h
@@ -83,14 +83,12 @@ template <class _FloatT>
 _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t);
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
   return ::strtof(__nptr, __endptr);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
   return ::strtod(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index e151709e65d03c..b404d1ca7ac080 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -177,8 +177,8 @@ _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char**
 #if defined(_LIBCPP_MSVCRT)
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
+inline
+    _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
   return ::_strtof_l(__nptr, __endptr, __loc);
 }
 
@@ -189,12 +189,10 @@ __str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __loca
 }
 #else
 template <>
-_LIBCPP_EXPORTED_FROM_ABI float
-__str_to_float_c_locale<float>(const char*, char**, __locale_t);
+_LIBCPP_EXPORTED_FROM_ABI float __str_to_float_c_locale<float>(const char*, char**, __locale_t);
 
 template <>
-_LIBCPP_EXPORTED_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char*, char**, __locale_t);
+_LIBCPP_EXPORTED_FROM_ABI long double __str_to_float_c_locale<long double>(const char*, char**, __locale_t);
 #endif
 
 template <>

>From e2be14fe6b04a5e1345d321c1cc4882a87a58773 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Mon, 21 Sep 2026 08:25:06 -0400
Subject: [PATCH 3/3] forward-declare __get_c_locale() and take __locale_t by
 value

---
 libcxx/include/__locale_dir/locale_base_api.h | 21 ++++++++++++-------
 .../locale_base_api/bsd_locale_fallbacks.h    |  2 +-
 libcxx/include/__locale_dir/num.h             |  6 +++---
 libcxx/include/__locale_dir/support/aix.h     | 19 ++++++++++-------
 .../include/__locale_dir/support/bsd_like.h   | 14 ++++++-------
 libcxx/include/__locale_dir/support/fuchsia.h |  2 +-
 libcxx/include/__locale_dir/support/linux.h   | 19 ++++++++++-------
 libcxx/include/__locale_dir/support/newlib.h  | 19 ++++++++++-------
 .../__locale_dir/support/no_locale/strtonum.h |  8 +++----
 libcxx/include/__locale_dir/support/openbsd.h | 10 ++++-----
 libcxx/include/__locale_dir/support/windows.h | 21 +++++++++++--------
 libcxx/src/support/win32/locale_win32.cpp     |  8 +++----
 12 files changed, 83 insertions(+), 66 deletions(-)

diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 92ff3abbfc2408..2e5e6d6011366d 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -55,7 +55,7 @@
 // namespace __locale {
 //  // required by the headers
 //  template <class FloatT>
-//  FloatT __str_to_float_c_locale(const char*, char**, __locale_t);
+//  FloatT __str_to_float_c_locale(const char*, char**);
 // }
 //
 // Character manipulation functions
@@ -165,6 +165,9 @@ namespace __locale {
 
 using __locale_t _LIBCPP_NODEBUG = locale_t;
 
+// Forward declared for use below.
+inline __locale_t __get_c_locale();
+
 #    if defined(_LIBCPP_BUILDING_LIBRARY)
 using __lconv_t _LIBCPP_NODEBUG = lconv;
 
@@ -185,24 +188,24 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return strtof_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  return strtof_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return strtod_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  return strtod_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return strtold_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  return strtold_l(__nptr, __endptr, __get_c_locale());
 }
 
 //
@@ -314,6 +317,8 @@ _LIBCPP_DIAGNOSTIC_POP
 } // namespace __locale
 _LIBCPP_END_NAMESPACE_STD
 
+#    include <__locale_dir/support/default/get_c_locale.h>
+
 #  endif // Compatibility definition of locale base APIs
 
 #endif // _LIBCPP_HAS_LOCALIZATION
diff --git a/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h b/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
index 8cdbe0cd15051c..973bbfd0f6cebd 100644
--- a/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
+++ b/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
@@ -29,7 +29,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct __locale_guard {
-  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
     if (__old_loc_)
diff --git a/libcxx/include/__locale_dir/num.h b/libcxx/include/__locale_dir/num.h
index 6395c6b6417dd5..f73b5961bbc7a1 100644
--- a/libcxx/include/__locale_dir/num.h
+++ b/libcxx/include/__locale_dir/num.h
@@ -306,17 +306,17 @@ _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<float>(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<float>(__a, __p2);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<double>(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<double>(__a, __p2);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
-  return __locale::__str_to_float_c_locale<long double>(__a, __p2, __locale::__get_c_locale());
+  return __locale::__str_to_float_c_locale<long double>(__a, __p2);
 }
 
 template <class _Tp>
diff --git a/libcxx/include/__locale_dir/support/aix.h b/libcxx/include/__locale_dir/support/aix.h
index 15de092b9cc6e4..78e9053c6e0a80 100644
--- a/libcxx/include/__locale_dir/support/aix.h
+++ b/libcxx/include/__locale_dir/support/aix.h
@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __locale {
 
 struct __locale_guard {
-  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
     if (__old_loc_)
@@ -63,6 +63,9 @@ inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_cur_max() { return MB_CUR
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 
+// Forward declared for use below.
+inline __locale_t __get_c_locale();
+
 #if defined(_LIBCPP_BUILDING_LIBRARY)
 using __lconv_t _LIBCPP_NODEBUG = std::lconv;
 
@@ -90,26 +93,26 @@ inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc)
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __locale_guard __current(__loc);
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  __locale_guard __current(__get_c_locale());
   return ::strtof(__nptr, __endptr);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __locale_guard __current(__loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  __locale_guard __current(__get_c_locale());
   return ::strtod(__nptr, __endptr);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  __locale_guard __current(__loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  __locale_guard __current(__get_c_locale());
   return ::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index 070f3dc3ad6ec0..1b8f1726e0da19 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -79,24 +79,24 @@ inline __locale_t __get_c_locale() {
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtof_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  return ::strtof_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtod_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  return ::strtod_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtold_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  return ::strtold_l(__nptr, __endptr, __get_c_locale());
 }
 
 //
diff --git a/libcxx/include/__locale_dir/support/fuchsia.h b/libcxx/include/__locale_dir/support/fuchsia.h
index 0b4c2681080327..f95ecbbb2e8303 100644
--- a/libcxx/include/__locale_dir/support/fuchsia.h
+++ b/libcxx/include/__locale_dir/support/fuchsia.h
@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __locale {
 
 struct __locale_guard {
-  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
     if (__old_loc_)
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 307cbf75fcfe02..8a616117b418ea 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -36,7 +36,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __locale {
 
 struct __locale_guard {
-  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
     if (__old_loc_)
@@ -63,6 +63,9 @@ struct __locale_guard {
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 
+// Forward declared for use below.
+inline __locale_t __get_c_locale();
+
 #if defined(_LIBCPP_BUILDING_LIBRARY)
 using __lconv_t _LIBCPP_NODEBUG = std::lconv;
 
@@ -86,24 +89,24 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtof_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  return ::strtof_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtod_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  return ::strtod_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtold_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  return ::strtold_l(__nptr, __endptr, __get_c_locale());
 }
 
 //
diff --git a/libcxx/include/__locale_dir/support/newlib.h b/libcxx/include/__locale_dir/support/newlib.h
index d64e1f0721c23a..79f3db185fb70e 100644
--- a/libcxx/include/__locale_dir/support/newlib.h
+++ b/libcxx/include/__locale_dir/support/newlib.h
@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __locale {
 
 struct __locale_guard {
-  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
     if (__old_loc_)
@@ -60,6 +60,9 @@ struct __locale_guard {
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 
+// Forward declared for use below.
+inline __locale_t __get_c_locale();
+
 #if defined(_LIBCPP_BUILDING_LIBRARY)
 using __lconv_t _LIBCPP_NODEBUG = std::lconv;
 
@@ -87,24 +90,24 @@ inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc)
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI float
-__str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtof_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  return ::strtof_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtod_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  return ::strtod_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::strtold_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  return ::strtold_l(__nptr, __endptr, __get_c_locale());
 }
 
 //
diff --git a/libcxx/include/__locale_dir/support/no_locale/strtonum.h b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
index 699eb3e6fa1736..2ad45f54ac4e61 100644
--- a/libcxx/include/__locale_dir/support/no_locale/strtonum.h
+++ b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
@@ -23,21 +23,21 @@ namespace __locale {
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
   return std::strtof(__nptr, __endptr);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
   return std::strtod(__nptr, __endptr);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
   return std::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/openbsd.h b/libcxx/include/__locale_dir/support/openbsd.h
index 8d3afe7c846daa..91897d70d1bf09 100644
--- a/libcxx/include/__locale_dir/support/openbsd.h
+++ b/libcxx/include/__locale_dir/support/openbsd.h
@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __locale {
 
 struct __locale_guard {
-  __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+  __locale_guard(locale_t __loc) : __old_loc_(::uselocale(__loc)) {}
 
   ~__locale_guard() {
     if (__old_loc_)
@@ -80,21 +80,21 @@ inline __lconv_t* __localeconv(__locale_t& __loc) {
 // Strtonum functions
 //
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
   return ::strtof(__nptr, __endptr);
 }
 
 template <>
-inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t) {
+inline _LIBCPP_HIDE_FROM_ABI double __str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
   return ::strtod(__nptr, __endptr);
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t) {
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
   return ::strtold(__nptr, __endptr);
 }
 
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index b404d1ca7ac080..6620dd22eaf570 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -154,6 +154,9 @@ class __locale_t {
   __lconv_storage* __lc_ = nullptr;
 };
 
+// Forward declared for use below.
+inline __locale_t __get_c_locale();
+
 #if defined(_LIBCPP_BUILDING_LIBRARY)
 _LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale(int __mask, const char* __locale, __locale_t __base);
 inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::_free_locale(__loc); }
@@ -173,32 +176,32 @@ _LIBCPP_EXPORTED_FROM_ABI const char* __get_locale_encoding(__locale_t __loc);
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
 template <class _FloatT>
-_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr, __locale_t __loc);
+_LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char** __endptr);
 #if defined(_LIBCPP_MSVCRT)
 
 template <>
 inline
-    _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::_strtof_l(__nptr, __endptr, __loc);
+    _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
+  return ::_strtof_l(__nptr, __endptr, __get_c_locale());
 }
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI long double
-__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::_strtold_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<long double>(const char* __nptr, char** __endptr) {
+  return ::_strtold_l(__nptr, __endptr, __get_c_locale());
 }
 #else
 template <>
-_LIBCPP_EXPORTED_FROM_ABI float __str_to_float_c_locale<float>(const char*, char**, __locale_t);
+_LIBCPP_EXPORTED_FROM_ABI float __str_to_float_c_locale<float>(const char*, char**);
 
 template <>
-_LIBCPP_EXPORTED_FROM_ABI long double __str_to_float_c_locale<long double>(const char*, char**, __locale_t);
+_LIBCPP_EXPORTED_FROM_ABI long double __str_to_float_c_locale<long double>(const char*, char**);
 #endif
 
 template <>
 inline _LIBCPP_HIDE_FROM_ABI double
-__str_to_float_c_locale<double>(const char* __nptr, char** __endptr, __locale_t __loc) {
-  return ::_strtod_l(__nptr, __endptr, __loc);
+__str_to_float_c_locale<double>(const char* __nptr, char** __endptr) {
+  return ::_strtod_l(__nptr, __endptr, __get_c_locale());
 }
 
 //
diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp
index e9660d06ed9200..a9853020c14240 100644
--- a/libcxx/src/support/win32/locale_win32.cpp
+++ b/libcxx/src/support/win32/locale_win32.cpp
@@ -300,14 +300,14 @@ const char* __get_locale_encoding(__locale_t loc) {
 //
 #if !defined(_LIBCPP_MSVCRT)
 template <>
-float __locale::__str_to_float_c_locale<float>(const char* nptr, char** endptr, __locale_t loc) {
-  __locale_guard __current(loc);
+float __locale::__str_to_float_c_locale<float>(const char* nptr, char** endptr) {
+  __locale_guard __current(__get_c_locale());
   return std::strtof(nptr, endptr);
 }
 
 template <>
-long double __locale::__str_to_float_c_locale<long double>(const char* nptr, char** endptr, __locale_t loc) {
-  __locale_guard __current(loc);
+long double __locale::__str_to_float_c_locale<long double>(const char* nptr, char** endptr) {
+  __locale_guard __current(__get_c_locale());
   return std::strtold(nptr, endptr);
 }
 #endif



More information about the libcxx-commits mailing list