[libcxx-commits] [libcxx] Libcpp has c8 rtomb mbrtoc8 clang experimental (PR #174378)
Victor Campos via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 5 02:05:16 PST 2026
https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/174378
>From d2976ca5c1bb839b9582cd55b6f2ec05319f3554 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Fri, 24 Oct 2025 09:36:31 +0100
Subject: [PATCH 1/3] [libcxx] Define `_LIBCPP_HAS_C8RTOMB_MBRTOC8` to true if
compiling with clang
Define `_LIBCPP_HAS_C8RTOMB_MBRTOC8` to `1` if compiling with clang.
Some tests involving functionality from `uchar.h`/`cuchar` fail when the
platform or the supporting C library does not provide support for the
corresponding features. These have been xfailed.
This patch will enable the adoption of newer picolibc versions.
---
libcxx/include/__config | 4 ++-
.../depr.c.headers/uchar_h.compile.pass.cpp | 5 ----
.../uchar_h_char8_t.compile.pass.cpp | 27 +++++++++++++++++
.../strings/c.strings/cuchar.compile.pass.cpp | 5 ----
.../c.strings/cuchar_char8_t.compile.pass.cpp | 27 +++++++++++++++++
.../c.strings/no_c8rtomb_mbrtoc8.verify.cpp | 30 -------------------
libcxx/utils/libcxx/test/features/misc.py | 17 +++++++++++
7 files changed, 74 insertions(+), 41 deletions(-)
create mode 100644 libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp
create mode 100644 libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp
delete mode 100644 libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
diff --git a/libcxx/include/__config b/libcxx/include/__config
index b4db39472ce31..8d313ef1165a4 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -826,7 +826,9 @@ typedef __char32_t char32_t;
// the latter depends on internal GNU libc details that are not appropriate
// to depend on here, so any declarations present when __cpp_char8_t is not
// defined are ignored.
-# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
+# if defined(__clang__)
+# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
+# elif _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
# else
# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
index a1560c8ee5853..c448ba83f4b38 100644
--- a/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
@@ -23,11 +23,6 @@
// __STDC_UTF_16__ may or may not be defined by the C standard library
// __STDC_UTF_32__ may or may not be defined by the C standard library
-#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
-ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
-ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
-#endif
-
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp
new file mode 100644
index 0000000000000..864ea2e0a7e59
--- /dev/null
+++ b/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
+// XFAIL: target={{.+}}-aix{{.*}}
+// XFAIL: android
+// XFAIL: darwin
+// XFAIL: freebsd
+// XFAIL: windows
+// XFAIL: glibc-no-char8_t-support
+// XFAIL: LIBCXX-PICOLIBC-FIXME
+
+// <uchar.h>
+
+#include <uchar.h>
+
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
+ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
index 2076384deb2b2..96b394a9934f8 100644
--- a/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
@@ -23,11 +23,6 @@
// __STDC_UTF_16__ may or may not be defined by the C standard library
// __STDC_UTF_32__ may or may not be defined by the C standard library
-#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
-ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
-ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
-#endif
-
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp
new file mode 100644
index 0000000000000..f78f925d72917
--- /dev/null
+++ b/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
+// XFAIL: target={{.+}}-aix{{.*}}
+// XFAIL: android
+// XFAIL: darwin
+// XFAIL: freebsd
+// XFAIL: windows
+// XFAIL: glibc-no-char8_t-support
+// XFAIL: LIBCXX-PICOLIBC-FIXME
+
+// <cuchar>
+
+#include <cuchar>
+
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
+ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp b/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
deleted file mode 100644
index 1d4a225668d80..0000000000000
--- a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-#include <uchar.h>
-
-#include "test_macros.h"
-
-// When C++ char8_t support is not enabled, definitions of these functions that
-// match the C2X declarations may still be present in the global namespace with
-// a char8_t typedef substituted for the C++ char8_t type. If so, these are not
-// the declarations we are looking for, so don't test for them.
-#if !defined(TEST_HAS_NO_CHAR8_T)
-using U = decltype(::c8rtomb);
-using V = decltype(::mbrtoc8);
-# if !_LIBCPP_HAS_C8RTOMB_MBRTOC8
-// expected-error at -3 {{no member named 'c8rtomb' in the global namespace}}
-// expected-error at -3 {{no member named 'mbrtoc8' in the global namespace}}
-# else
-// expected-no-diagnostics
-# endif
-#else
-// expected-no-diagnostics
-#endif
diff --git a/libcxx/utils/libcxx/test/features/misc.py b/libcxx/utils/libcxx/test/features/misc.py
index 738e3d8bb207c..7c3bc37b7a76d 100644
--- a/libcxx/utils/libcxx/test/features/misc.py
+++ b/libcxx/utils/libcxx/test/features/misc.py
@@ -198,6 +198,23 @@ def _mingwSupportsModules(cfg):
""",
),
),
+ # Check for Glibc < 2.36, where there was no support for char8_t functions
+ Feature(
+ name="glibc-no-char8_t-support",
+ when=lambda cfg: "__GLIBC__" in compilerMacros(cfg)
+ and not sourceBuilds(
+ cfg,
+ """
+ #include <uchar.h>
+ #include <wchar.h>
+ mbstate_t s;
+ int main(void) {
+ char8_t c;
+ return mbrtoc8(&c, "", 0, &s);
+ }
+ """,
+ ),
+ ),
# Whether Bash can run on the executor.
# This is not always the case, for example when running on embedded systems.
#
>From f93929d863fea0f9e797a77cda6763739ed870d7 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Mon, 5 Jan 2026 09:10:49 +0000
Subject: [PATCH 2/3] Declare char8 functions in the global namespace
---
libcxx/include/cuchar | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libcxx/include/cuchar b/libcxx/include/cuchar
index 38505eb336f84..419248e58fd5a 100644
--- a/libcxx/include/cuchar
+++ b/libcxx/include/cuchar
@@ -75,6 +75,11 @@ using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
_LIBCPP_END_NAMESPACE_STD
+#if _LIBCPP_HAS_C8RTOMB_MBRTOC8
+using ::mbrtoc8 _LIBCPP_USING_IF_EXISTS;
+using ::c8rtomb _LIBCPP_USING_IF_EXISTS;
+#endif
+
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
#endif // _LIBCPP_CUCHAR
>From 7a6b17da1d046de1860419633cda1acb7b3c3a26 Mon Sep 17 00:00:00 2001
From: Victor Campos <github at victorcampos.me>
Date: Mon, 5 Jan 2026 10:05:07 +0000
Subject: [PATCH 3/3] Fix preprocessor directive formatting in cuchar
---
libcxx/include/cuchar | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/cuchar b/libcxx/include/cuchar
index 419248e58fd5a..8385a48d44194 100644
--- a/libcxx/include/cuchar
+++ b/libcxx/include/cuchar
@@ -75,10 +75,10 @@ using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
_LIBCPP_END_NAMESPACE_STD
-#if _LIBCPP_HAS_C8RTOMB_MBRTOC8
+# if _LIBCPP_HAS_C8RTOMB_MBRTOC8
using ::mbrtoc8 _LIBCPP_USING_IF_EXISTS;
using ::c8rtomb _LIBCPP_USING_IF_EXISTS;
-#endif
+# endif
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
More information about the libcxx-commits
mailing list