[libcxx-commits] [libcxx] [libc++] Don't error when including <wchar.h> or <wctype.h> without wide character support (PR #108639)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Sep 13 12:56:03 PDT 2024
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/108639
Instead, make the headers empty like we do for all the other carve-outs.
>From 53e43a5165623555facbe4c3db69f1d8623fa8fc Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 13 Sep 2024 15:30:21 -0400
Subject: [PATCH] [libc++] Don't error when including <wchar.h> or <wctype.h>
without wide character support
Instead, make the headers empty like we do for all the other carve-outs.
---
libcxx/include/wchar.h | 15 ++++++---------
libcxx/include/wctype.h | 5 -----
.../depr/depr.c.headers/wctype_h.compile.pass.cpp | 2 +-
.../test/std/strings/c.strings/cwctype.pass.cpp | 2 +-
4 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/libcxx/include/wchar.h b/libcxx/include/wchar.h
index d4268c6d2c2442..c965b28e57c6c7 100644
--- a/libcxx/include/wchar.h
+++ b/libcxx/include/wchar.h
@@ -108,11 +108,6 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
# include <__config>
# include <stddef.h>
-# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-# error \
- "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
-# endif
-
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
@@ -142,7 +137,8 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
# endif
# endif
-# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
extern "C++" {
inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
return (wchar_t*)wcschr(__s, __c);
@@ -197,15 +193,16 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t
return __libcpp_wmemchr(__s, __c, __n);
}
}
-# endif
+# endif
-# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
+# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
extern "C" {
size_t mbsnrtowcs(
wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps);
size_t wcsnrtombs(
char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps);
} // extern "C"
-# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
+# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
+# endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
#endif // _LIBCPP_WCHAR_H
diff --git a/libcxx/include/wctype.h b/libcxx/include/wctype.h
index c76ec5a3f06085..9f378eaf8202a1 100644
--- a/libcxx/include/wctype.h
+++ b/libcxx/include/wctype.h
@@ -46,11 +46,6 @@ wctrans_t wctrans(const char* property);
#include <__config>
-#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-# error \
- "The <wctype.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
-#endif
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
diff --git a/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
index 094f7713bb365c..35b294532b2bd2 100644
--- a/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
// <wctype.h>
diff --git a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
index d421bea5a5672a..5bc2531d6f6ac7 100644
--- a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
@@ -8,7 +8,7 @@
// <cwctype>
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
#include <cwctype>
#include <type_traits>
More information about the libcxx-commits
mailing list