|
| 1 | +From 9c2048aa841cafd80e0c6752cf6872a9d42e6eb3 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Steven Cooreman <steven.cooreman@gmail.com> |
| 3 | +Date: Tue, 18 Feb 2025 12:12:23 +0100 |
| 4 | +Subject: [libc++] Do not guard inclusion of wchar.h with |
| 5 | + _LIBCPP_HAS_WIDE_CHARACTERS (#126924) |
| 6 | + |
| 7 | +`mbstate_t` needs to be visible to libcpp, even when it is not providing |
| 8 | +wide |
| 9 | +character functionality (i.e. `_LIBCPP_HAS_WIDE_CHARACTERS` is turned |
| 10 | +off) |
| 11 | +and thus not using any of the C library's wide character functions. |
| 12 | + |
| 13 | +There are C libraries (such as newlib-nano/nanolib/picolibc) which do |
| 14 | +provide their definition of `mbstate_t` in `<wchar.h>` even though they |
| 15 | +do not |
| 16 | +come with wide character functions. |
| 17 | + |
| 18 | +Since there is a way to conditionally include the C library's |
| 19 | +`<wchar.h>` |
| 20 | +only if it exists, we should rely on the fact that if it exists, it will |
| 21 | +provide `mbstate_t`. Removing this guard will allow using libc++ on top |
| 22 | +of |
| 23 | +newlib-nano/picolibc while not breaking the cases where it is used on |
| 24 | +top |
| 25 | +of a C library which doesn't provide `<wchar.h>` (since it would then |
| 26 | +still |
| 27 | +go look for `<uchar.h>` or error out). |
| 28 | + |
| 29 | +(cherry picked from commit 762001118c068317ec67274221497be2e6499c6a) |
| 30 | +--- |
| 31 | + libcxx/include/__mbstate_t.h | 8 ++++---- |
| 32 | + 1 file changed, 4 insertions(+), 4 deletions(-) |
| 33 | + |
| 34 | +diff --git a/libcxx/include/__mbstate_t.h b/libcxx/include/__mbstate_t.h |
| 35 | +index e013384454b4..c23ea7113ca7 100644 |
| 36 | +--- a/libcxx/include/__mbstate_t.h |
| 37 | ++++ b/libcxx/include/__mbstate_t.h |
| 38 | +@@ -43,12 +43,12 @@ |
| 39 | + # include <bits/types/mbstate_t.h> // works on most Unixes |
| 40 | + #elif __has_include(<sys/_types/_mbstate_t.h>) |
| 41 | + # include <sys/_types/_mbstate_t.h> // works on Darwin |
| 42 | +-#elif _LIBCPP_HAS_WIDE_CHARACTERS && __has_include_next(<wchar.h>) |
| 43 | +-# include_next <wchar.h> // fall back to the C standard provider of mbstate_t |
| 44 | ++#elif __has_include_next(<wchar.h>) |
| 45 | ++# include_next <wchar.h> // use the C standard provider of mbstate_t if present |
| 46 | + #elif __has_include_next(<uchar.h>) |
| 47 | +-# include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible |
| 48 | ++# include_next <uchar.h> // Try <uchar.h> in absence of <wchar.h> for mbstate_t |
| 49 | + #else |
| 50 | +-# error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform." |
| 51 | ++# error "We don't know how to get the definition of mbstate_t on your platform." |
| 52 | + #endif |
| 53 | + |
| 54 | + #endif // _LIBCPP___MBSTATE_T_H |
| 55 | +-- |
| 56 | +2.47.1 |
| 57 | + |
0 commit comments