[libcxx-commits] [libcxx] [AIX][libc++] Fix redefinition of wchar_t overloads on AIX (PR #201432)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 7 21:03:10 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Himadhith

<details>
<summary>Changes</summary>

On AIX, the system headers have a circular dependency: `wctype.h → wchar.h → wctype.h` which causes wchar.h to be processed multiple times. 

The existing `_LIBCPP_WCHAR_H` include guard does not protect because wchar.h is a textual header and they get their own pre-processing per module compilation. 

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


2 Files Affected:

- (modified) libcxx/include/wchar.h (+3) 
- (modified) libcxx/test/extensions/clang/clang_modules_include.gen.py (-2) 


``````````diff
diff --git a/libcxx/include/wchar.h b/libcxx/include/wchar.h
index a932dd266b862..31ff5490c9885 100644
--- a/libcxx/include/wchar.h
+++ b/libcxx/include/wchar.h
@@ -137,6 +137,8 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
 
 #    if _LIBCPP_HAS_WIDE_CHARACTERS
 #      if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
+#        if defined(_AIX) && !defined(_LIBCPP_WCHAR_H_OVERLOADS)
+#          define _LIBCPP_WCHAR_H_OVERLOADS
 extern "C++" {
 inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
   return (wchar_t*)wcschr(__s, __c);
@@ -191,6 +193,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t
   return __libcpp_wmemchr(__s, __c, __n);
 }
 }
+#        endif // _LIBCPP_WCHAR_H_OVERLOADS
 #      endif
 
 #      if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
diff --git a/libcxx/test/extensions/clang/clang_modules_include.gen.py b/libcxx/test/extensions/clang/clang_modules_include.gen.py
index 28661049d6e85..f0de60bacd7a7 100644
--- a/libcxx/test/extensions/clang/clang_modules_include.gen.py
+++ b/libcxx/test/extensions/clang/clang_modules_include.gen.py
@@ -30,8 +30,6 @@
 # TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
 # UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
 
-# TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
-# UNSUPPORTED: LIBCXX-AIX-FIXME
 
 # UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/201432


More information about the libcxx-commits mailing list