[libcxx-commits] [libcxx] [libc++][modules] 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
Mon Sep 16 05:26:57 PDT 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/108639

>From dc7bfaab4c7c77fe33a64dea3d43a49af9d9803e 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/__std_clang_module                | 16 ++++------------
 libcxx/include/wchar.h                           | 15 ++++++---------
 libcxx/include/wctype.h                          |  5 -----
 libcxx/modules/std.compat.cppm.in                |  8 ++------
 libcxx/modules/std.cppm.in                       |  8 ++------
 .../depr/depr.c.headers/wchar_h.compile.pass.cpp |  2 +-
 .../depr.c.headers/wctype_h.compile.pass.cpp     |  2 +-
 .../test/std/strings/c.strings/cwchar.pass.cpp   |  2 +-
 .../cwchar_include_order1.compile.verify.cpp     |  2 +-
 .../cwchar_include_order2.compile.verify.cpp     |  2 +-
 .../test/std/strings/c.strings/cwctype.pass.cpp  |  2 +-
 libcxx/utils/libcxx/header_information.py        |  7 -------
 12 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module
index 572528669a1e15..a21ed26addfe8e 100644
--- a/libcxx/include/__std_clang_module
+++ b/libcxx/include/__std_clang_module
@@ -73,12 +73,8 @@
 #include <ctime>
 #include <ctype.h>
 #include <cuchar>
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwchar>
-#endif
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwctype>
-#endif
+#include <cwchar>
+#include <cwctype>
 #include <deque>
 #include <errno.h>
 #include <exception>
@@ -193,9 +189,5 @@
 #include <variant>
 #include <vector>
 #include <version>
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <wchar.h>
-#endif
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <wctype.h>
-#endif
+#include <wchar.h>
+#include <wctype.h>
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/modules/std.compat.cppm.in b/libcxx/modules/std.compat.cppm.in
index 0f547a2dc8b715..797b413f68e272 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -38,12 +38,8 @@ module;
 #include <cstring>
 #include <ctime>
 #include <cuchar>
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwchar>
-#endif
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwctype>
-#endif
+#include <cwchar>
+#include <cwctype>
 
 // *** Headers not yet available ***
 //
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index 653f9933ba67c7..0575774f6f42fd 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -57,12 +57,8 @@ module;
 #include <cstring>
 #include <ctime>
 #include <cuchar>
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwchar>
-#endif
-#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
-#  include <cwctype>
-#endif
+#include <cwchar>
+#include <cwctype>
 #include <deque>
 #include <exception>
 #include <execution>
diff --git a/libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp
index ae08ebd6ad8215..98d028c5181d59 100644
--- a/libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
 
 // <wchar.h>
 
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/cwchar.pass.cpp b/libcxx/test/std/strings/c.strings/cwchar.pass.cpp
index 3aa660fb919b51..0caf4b9913b509 100644
--- a/libcxx/test/std/strings/c.strings/cwchar.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cwchar.pass.cpp
@@ -8,7 +8,7 @@
 
 // <cwchar>
 
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
 
 #include <cwchar>
 #include <ctime>
diff --git a/libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp b/libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
index 4b5460a54859fb..10560e51774ba3 100644
--- a/libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
+++ b/libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
@@ -8,7 +8,7 @@
 
 // <cwchar>
 
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
 
 // Tests that include ordering does not affect the definition of wcsstr.
 // See: https://llvm.org/PR62638
diff --git a/libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp b/libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp
index 0222ac018d687b..4be79999bd1721 100644
--- a/libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp
+++ b/libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp
@@ -8,7 +8,7 @@
 
 // <cwchar>
 
-// XFAIL: no-wide-characters
+// UNSUPPORTED: no-wide-characters
 
 // Tests that include ordering does not affect the definition of wcsstr.
 // See: https://llvm.org/PR62638
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>
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index 694402141e1fab..fd48b35a88b558 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -30,13 +30,6 @@
     "streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "syncstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
-
-    # headers with #error directives
-    "wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
-    "wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
-    # transitive includers of the above headers
-    "cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
-    "cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
 }
 
 lit_header_restrictions = {



More information about the libcxx-commits mailing list