[libcxx-commits] [libcxx] aa2a7f4 - [libc++] Fix the locale base API on Linux with musl (#167980)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 27 17:14:09 PST 2025


Author: Mr. Walls
Date: 2025-11-28T09:14:05+08:00
New Revision: aa2a7f4eb1b130e9e41d9a87bffcaa47876a97fc

URL: https://github.com/llvm/llvm-project/commit/aa2a7f4eb1b130e9e41d9a87bffcaa47876a97fc
DIFF: https://github.com/llvm/llvm-project/commit/aa2a7f4eb1b130e9e41d9a87bffcaa47876a97fc.diff

LOG: [libc++] Fix the locale base API on Linux with musl (#167980)

This pull request addresses an issue encountered when building
**libcxx** with certain configurations (`-D_LIBCPP_HAS_MUSL_LIBC` &
`-D__linux__`) that lack the `_GNU_SOURCE` definition. Specifically,
this issue arises if the system **musl libc** is built with
`_BSD_SOURCE` instead of `_GNU_SOURCE`. The resultant configuration
leads to problems with the "Strtonum functions" in the file
[libcxx/include/__locale_dir/support/linux.h](https://github.com/llvm/llvm-project/tree/master/libcxx/include/__locale_dir/support/linux.h),
affecting the following functions:

- `__strtof`
- `__strtod`
- `__strtold`

**Error messages displayed include**:
```console
error: no member named 'strtof_l' in the global namespace
```
```console
error: no member named 'strtod_l' in the global namespace
```
```console
error: no member named 'strtold_l' in the global namespace
```

For more insight, relevant code can be accessed
[here](https://github.com/llvm/llvm-project/blob/79cd1b7a25cdbf42c7234999ae9bc51db30af1f0/libcxx/include/__locale_dir/support/linux.h#L85-L95).

Added: 
    

Modified: 
    libcxx/include/__locale_dir/support/linux.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 1a589be49bf1d..deb657d4faced 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -83,15 +83,30 @@ 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) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
   return ::strtof_l(__nptr, __endptr, __loc);
+#else
+  (void)__loc;
+  return ::strtof(__nptr, __endptr);
+#endif
 }
 
 inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
   return ::strtod_l(__nptr, __endptr, __loc);
+#else
+  (void)__loc;
+  return ::strtod(__nptr, __endptr);
+#endif
 }
 
 inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
   return ::strtold_l(__nptr, __endptr, __loc);
+#else
+  (void)__loc;
+  return ::strtold(__nptr, __endptr);
+#endif
 }
 
 //


        


More information about the libcxx-commits mailing list