[libcxx-commits] [libcxx] [libc++] Do not guard inclusion of wchar.h with _LIBCPP_HAS_WIDE_CHARACTERS (PR #126924)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 12 07:27:26 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Steven Cooreman (stevew817)

<details>
<summary>Changes</summary>

`mbstate_t` needs to be visible to libc++, even when it is not relying on wide character functionality in the C library. C90 amendment 1 says that this type is to be visible through `wchar.h`. That header file should be provided by the C standard library even when that library is not implementing wchar functions (such as newlib with `--nano-formatted-io`).

The reason this guard was in place is purely historical, I believe. Tracing the modification history, I can't find any reason other than maybe `has_include_next` not having been in place at the time of creation of this file. Looking at the other include chains, libc++'s `<wchar.h>` [already unconditionally includes the underlying C lib's `wchar.h`](https://github.com/llvm/llvm-project/blob/257754011c741d96a9adbcd4858706a59bdca085/libcxx/include/wchar.h#L112C1-L117C9), so I don't really see why this guard needs to still be in place. If the C lib is providing `wchar.h`, it can be used to get hold of `mbstate_t` regardless of whether or not libc++ is allowed to call the wide char functions or not.

Tagging @<!-- -->ldionne for review according to the maintainer file.

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


1 Files Affected:

- (modified) libcxx/include/__mbstate_t.h (+4-4) 


``````````diff
diff --git a/libcxx/include/__mbstate_t.h b/libcxx/include/__mbstate_t.h
index e013384454b41..e32c1dbd0c7ab 100644
--- a/libcxx/include/__mbstate_t.h
+++ b/libcxx/include/__mbstate_t.h
@@ -43,12 +43,12 @@
 #  include <bits/types/mbstate_t.h> // works on most Unixes
 #elif __has_include(<sys/_types/_mbstate_t.h>)
 #  include <sys/_types/_mbstate_t.h> // works on Darwin
-#elif _LIBCPP_HAS_WIDE_CHARACTERS && __has_include_next(<wchar.h>)
-#  include_next <wchar.h> // fall back to the C standard provider of mbstate_t
+#elif __has_include_next(<wchar.h>)
+#  include_next <wchar.h> // user the C standard provider of mbstate_t if present
 #elif __has_include_next(<uchar.h>)
-#  include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible
+#  include_next <uchar.h> // <uchar.h> can alternatively provide mbstate_t
 #else
-#  error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
+#  error "We don't know how to get the definition of mbstate_t on your platform."
 #endif
 
 #endif // _LIBCPP___MBSTATE_T_H

``````````

</details>


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


More information about the libcxx-commits mailing list