[libcxx-commits] [libcxx] [AIX][libc++] Forward-declare locale functions in aix.h when _XOPEN_SOURCE < 700 (PR #220508)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 2 01:00:07 PDT 2026


https://github.com/Himadhith created https://github.com/llvm/llvm-project/pull/220508

On AIX, the following locale functions `(uselocale/newlocale/freelocale/duplocale)` are only declared in `usr/include/locale.h` when `_XOPEN_SOURCE > 700`. 

This causes a failure in the test `libcxx/test/extensions/posix/xopen_source.gen.py` which tests `_XOPEN_SOURCE ` against 500, 600 and 700, with the following error:
```
# | /home/himadhit/llvm/dev/build/build-aix-libcxx/64/libcxx/test-suite-install/include/c++/v1/__locale_dir/support/aix.h:36:72: error: no member named 'uselocale' in the global namespace; did you mean 'setlocale'?
```

The fix here is to forward declare those 4 functions inside `aix.h` and make them visible. 


>From a0bfe624a4044448236c7e591ba7839787a60e3b Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Wed, 2 Sep 2026 03:38:09 -0400
Subject: [PATCH] [AIX][libc++] Forward-declare locale functions in aix.h when
 _XOPEN_SOURCE_ < 700

---
 libcxx/include/__locale_dir/support/aix.h        | 10 ++++++++++
 libcxx/test/extensions/posix/xopen_source.gen.py |  4 ----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/__locale_dir/support/aix.h b/libcxx/include/__locale_dir/support/aix.h
index 4ab52793ae3c1..839824d273845 100644
--- a/libcxx/include/__locale_dir/support/aix.h
+++ b/libcxx/include/__locale_dir/support/aix.h
@@ -25,6 +25,16 @@
 #  include <wctype.h>
 #endif
 
+// Forward declare for _XOPEN_SOURCE=500 and _XOPEN_SOURCE=600
+ #if defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 700
+ extern "C" {
+ locale_t newlocale(int, const char*, locale_t) noexcept;
+ locale_t duplocale(locale_t) noexcept;
+ locale_t uselocale(locale_t) noexcept;
+ void freelocale(locale_t) noexcept;
+ }
+ #endif // defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 700
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
diff --git a/libcxx/test/extensions/posix/xopen_source.gen.py b/libcxx/test/extensions/posix/xopen_source.gen.py
index ac04e38bde38a..bd14e691de5af 100644
--- a/libcxx/test/extensions/posix/xopen_source.gen.py
+++ b/libcxx/test/extensions/posix/xopen_source.gen.py
@@ -12,10 +12,6 @@
 #
 # https://llvm.org/PR117630
 
-# The AIX localization support uses some functions as part of their headers that require a
-# recent value of _XOPEN_SOURCE.
-# UNSUPPORTED: LIBCXX-AIX-FIXME
-
 # FreeBSD maps _XOPEN_SOURCE=500 to __ISO_C_VISIBLE=1990 (see <sys/_visible.h>), which hides
 # everything C99 added to the C library, even in C++ mode. libc++ needs some of those
 # additions to provide a conforming library at all.



More information about the libcxx-commits mailing list