Skip to content

Commit 165f0e8

Browse files
authored
[libc++][modules] Don't error when including <wchar.h> or <wctype.h> without wide character support (#108639)
Instead, make the headers empty like we do for all the other carve-outs.
1 parent 79c4ece commit 165f0e8

File tree

12 files changed

+20
-51
lines changed

12 files changed

+20
-51
lines changed

libcxx/include/__std_clang_module

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@
7373
#include <ctime>
7474
#include <ctype.h>
7575
#include <cuchar>
76-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
77-
# include <cwchar>
78-
#endif
79-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
80-
# include <cwctype>
81-
#endif
76+
#include <cwchar>
77+
#include <cwctype>
8278
#include <deque>
8379
#include <errno.h>
8480
#include <exception>
@@ -193,9 +189,5 @@
193189
#include <variant>
194190
#include <vector>
195191
#include <version>
196-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
197-
# include <wchar.h>
198-
#endif
199-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
200-
# include <wctype.h>
201-
#endif
192+
#include <wchar.h>
193+
#include <wctype.h>

libcxx/include/wchar.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
108108
# include <__config>
109109
# include <stddef.h>
110110

111-
# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
112-
# error \
113-
"The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
114-
# endif
115-
116111
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
117112
# pragma GCC system_header
118113
# endif
@@ -142,7 +137,8 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
142137
# endif
143138
# endif
144139

145-
# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
140+
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
141+
# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
146142
extern "C++" {
147143
inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
148144
return (wchar_t*)wcschr(__s, __c);
@@ -197,15 +193,16 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t
197193
return __libcpp_wmemchr(__s, __c, __n);
198194
}
199195
}
200-
# endif
196+
# endif
201197

202-
# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
198+
# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
203199
extern "C" {
204200
size_t mbsnrtowcs(
205201
wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps);
206202
size_t wcsnrtombs(
207203
char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps);
208204
} // extern "C"
209-
# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
205+
# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
206+
# endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
210207

211208
#endif // _LIBCPP_WCHAR_H

libcxx/include/wctype.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ wctrans_t wctrans(const char* property);
4646

4747
#include <__config>
4848

49-
#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
50-
# error \
51-
"The <wctype.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
52-
#endif
53-
5449
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5550
# pragma GCC system_header
5651
#endif

libcxx/modules/std.compat.cppm.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ module;
3838
#include <cstring>
3939
#include <ctime>
4040
#include <cuchar>
41-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
42-
# include <cwchar>
43-
#endif
44-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
45-
# include <cwctype>
46-
#endif
41+
#include <cwchar>
42+
#include <cwctype>
4743

4844
// *** Headers not yet available ***
4945
//

libcxx/modules/std.cppm.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ module;
5757
#include <cstring>
5858
#include <ctime>
5959
#include <cuchar>
60-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
61-
# include <cwchar>
62-
#endif
63-
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
64-
# include <cwctype>
65-
#endif
60+
#include <cwchar>
61+
#include <cwctype>
6662
#include <deque>
6763
#include <exception>
6864
#include <execution>

libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// XFAIL: no-wide-characters
9+
// UNSUPPORTED: no-wide-characters
1010

1111
// <wchar.h>
1212

libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// XFAIL: no-wide-characters
9+
// UNSUPPORTED: no-wide-characters
1010

1111
// <wctype.h>
1212

libcxx/test/std/strings/c.strings/cwchar.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <cwchar>
1010

11-
// XFAIL: no-wide-characters
11+
// UNSUPPORTED: no-wide-characters
1212

1313
#include <cwchar>
1414
#include <ctime>

libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <cwchar>
1010

11-
// XFAIL: no-wide-characters
11+
// UNSUPPORTED: no-wide-characters
1212

1313
// Tests that include ordering does not affect the definition of wcsstr.
1414
// See: https://llvm.org/PR62638

libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <cwchar>
1010

11-
// XFAIL: no-wide-characters
11+
// UNSUPPORTED: no-wide-characters
1212

1313
// Tests that include ordering does not affect the definition of wcsstr.
1414
// See: https://llvm.org/PR62638

libcxx/test/std/strings/c.strings/cwctype.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <cwctype>
1010

11-
// XFAIL: no-wide-characters
11+
// UNSUPPORTED: no-wide-characters
1212

1313
#include <cwctype>
1414
#include <type_traits>

libcxx/utils/libcxx/header_information.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030
"streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
3131
"strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
3232
"syncstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
33-
34-
# headers with #error directives
35-
"wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
36-
"wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
37-
# transitive includers of the above headers
38-
"cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
39-
"cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
4033
}
4134

4235
lit_header_restrictions = {

0 commit comments

Comments
 (0)