[libcxx-commits] [libcxx] [libc++] Guard unchecked uses of wchar_t and char8_t in tests (PR #229255)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 5 15:49:56 PDT 2026
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/229255
A few places in the test suite were not properly guarding based on whether wide characters or char8_t are available.
>From 7110b3b9bb6cc3e56e49c945e07254499f550755 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 5 Oct 2026 13:21:46 -0400
Subject: [PATCH] [libc++] Guard unchecked uses of wchar_t and char8_t in tests
A few places in the test suite were not properly guarding based on
whether wide characters or char8_t are available.
---
.../specialized_algorithms.compile.pass.cpp | 2 ++
.../format.functions.tests.h | 2 +-
.../locale.num.get/types.pass.cpp | 9 ++++---
.../locale.time.get/types.pass.cpp | 11 +++++---
.../locale.time.put/types.pass.cpp | 9 ++++---
.../codecvt_utf16_length.pass.cpp | 26 ++++++++++---------
.../saturating_div.compile.pass.cpp | 2 +-
.../saturating_sub.compile.pass.cpp | 2 +-
.../std/re/re.iter/re.tokiter/types.pass.cpp | 4 ++-
.../re.regex.const/constants.pass.cpp | 4 ++-
libcxx/test/std/re/re.regex/types.pass.cpp | 4 ++-
.../re.results.size/max_size.pass.cpp | 4 ++-
libcxx/test/std/re/re.results/types.pass.cpp | 4 ++-
.../enable_borrowed_range.compile.pass.cpp | 4 +++
14 files changed, 57 insertions(+), 30 deletions(-)
diff --git a/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp b/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp
index 22e44f897d57fcb..8d4ff6304f8a11e 100644
--- a/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp
@@ -88,8 +88,10 @@ template <class CharT>
using obi = std::ostreambuf_iterator<CharT>;
static_assert(has_alg<Alg::__copy, iter_pair<char*, char*>, single_iter<obi<char>>>);
static_assert(has_alg<Alg::__copy, iter_pair<const char*, const char*>, single_iter<obi<char>>>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
static_assert(has_alg<Alg::__copy, iter_pair<wchar_t*, wchar_t*>, single_iter<obi<wchar_t>>>);
static_assert(has_alg<Alg::__copy, iter_pair<const wchar_t*, const wchar_t*>, single_iter<obi<wchar_t>>>);
static_assert(!has_alg<Alg::__copy, iter_pair<char*, char*>, single_iter<obi<wchar_t>>>);
+#endif
} // namespace ostreambuf_iterator
diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
index eb4b7a1d2e62f0d..51d6ec3c4783639 100644
--- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
+++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
@@ -966,7 +966,7 @@ void test_status(TestFunction check, ExceptionTest check_exception) {
template <class CharT, class TestFunction, class ExceptionTest>
void format_tests(TestFunction check, ExceptionTest check_exception) {
test_char<CharT>(check, check_exception);
-#if _LIBCPP_HAS_WIDE_CHARACTERS
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
if (std::same_as<CharT, wchar_t>) // avoid testing twice
test_char_to_wchar(check, check_exception);
#endif
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/types.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/types.pass.cpp
index ea9ea9fcf0b603b..c1e0fe4a7458234 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/types.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/types.pass.cpp
@@ -25,11 +25,14 @@
int main(int, char**)
{
static_assert((std::is_base_of<std::locale::facet, std::num_get<char> >::value), "");
- static_assert((std::is_base_of<std::locale::facet, std::num_get<wchar_t> >::value), "");
static_assert((std::is_same<std::num_get<char>::char_type, char>::value), "");
- static_assert((std::is_same<std::num_get<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::num_get<char>::iter_type, std::istreambuf_iterator<char> >::value), "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ static_assert((std::is_base_of<std::locale::facet, std::num_get<wchar_t> >::value), "");
+ static_assert((std::is_same<std::num_get<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::num_get<wchar_t>::iter_type, std::istreambuf_iterator<wchar_t> >::value), "");
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get/types.pass.cpp b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get/types.pass.cpp
index 8d8889551444da3..84cff8592030c28 100644
--- a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get/types.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get/types.pass.cpp
@@ -32,13 +32,16 @@
int main(int, char**)
{
static_assert((std::is_base_of<std::locale::facet, std::time_get<char> >::value), "");
- static_assert((std::is_base_of<std::locale::facet, std::time_get<wchar_t> >::value), "");
static_assert((std::is_base_of<std::time_base, std::time_get<char> >::value), "");
- static_assert((std::is_base_of<std::time_base, std::time_get<wchar_t> >::value), "");
static_assert((std::is_same<std::time_get<char>::char_type, char>::value), "");
- static_assert((std::is_same<std::time_get<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::time_get<char>::iter_type, std::istreambuf_iterator<char> >::value), "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ static_assert((std::is_base_of<std::locale::facet, std::time_get<wchar_t> >::value), "");
+ static_assert((std::is_base_of<std::time_base, std::time_get<wchar_t> >::value), "");
+ static_assert((std::is_same<std::time_get<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::time_get<wchar_t>::iter_type, std::istreambuf_iterator<wchar_t> >::value), "");
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/localization/locale.categories/category.time/locale.time.put/types.pass.cpp b/libcxx/test/std/localization/locale.categories/category.time/locale.time.put/types.pass.cpp
index 8a661a78cb12900..07249639340e32d 100644
--- a/libcxx/test/std/localization/locale.categories/category.time/locale.time.put/types.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.time/locale.time.put/types.pass.cpp
@@ -25,11 +25,14 @@
int main(int, char**)
{
static_assert((std::is_base_of<std::locale::facet, std::time_put<char> >::value), "");
- static_assert((std::is_base_of<std::locale::facet, std::time_put<wchar_t> >::value), "");
static_assert((std::is_same<std::time_put<char>::char_type, char>::value), "");
- static_assert((std::is_same<std::time_put<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::time_put<char>::iter_type, std::ostreambuf_iterator<char> >::value), "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ static_assert((std::is_base_of<std::locale::facet, std::time_put<wchar_t> >::value), "");
+ static_assert((std::is_same<std::time_put<wchar_t>::char_type, wchar_t>::value), "");
static_assert((std::is_same<std::time_put<wchar_t>::iter_type, std::ostreambuf_iterator<wchar_t> >::value), "");
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp
index 68898957599f3d1..b52db432240b88d 100644
--- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp
+++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp
@@ -42,7 +42,7 @@ struct TestHelper<CharT, 4> {
template <class CharT>
void TestHelper<CharT, 2>::test() {
{
- typedef std::codecvt_utf16<char16_t> C;
+ typedef std::codecvt_utf16<CharT> C;
C c;
char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -65,7 +65,7 @@ void TestHelper<CharT, 2>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char16_t, 0x1000> C;
+ typedef std::codecvt_utf16<CharT, 0x1000> C;
C c;
char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -88,7 +88,7 @@ void TestHelper<CharT, 2>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char16_t, 0x10ffff, std::consume_header> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::consume_header> C;
C c;
char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -111,7 +111,7 @@ void TestHelper<CharT, 2>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char16_t, 0x10ffff, std::little_endian> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::little_endian> C;
C c;
char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -134,7 +134,7 @@ void TestHelper<CharT, 2>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char16_t, 0x1000, std::little_endian> C;
+ typedef std::codecvt_utf16<CharT, 0x1000, std::little_endian> C;
C c;
char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -157,7 +157,7 @@ void TestHelper<CharT, 2>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char16_t, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
C c;
char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -184,7 +184,7 @@ void TestHelper<CharT, 2>::test() {
template <class CharT>
void TestHelper<CharT, 4>::test() {
{
- typedef std::codecvt_utf16<char32_t> C;
+ typedef std::codecvt_utf16<CharT> C;
C c;
char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -207,7 +207,7 @@ void TestHelper<CharT, 4>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char32_t, 0x1000> C;
+ typedef std::codecvt_utf16<CharT, 0x1000> C;
C c;
char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -230,7 +230,7 @@ void TestHelper<CharT, 4>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char32_t, 0x10ffff, std::consume_header> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::consume_header> C;
C c;
char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
std::mbstate_t m;
@@ -253,7 +253,7 @@ void TestHelper<CharT, 4>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::little_endian> C;
C c;
char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -276,7 +276,7 @@ void TestHelper<CharT, 4>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char32_t, 0x1000, std::little_endian> C;
+ typedef std::codecvt_utf16<CharT, 0x1000, std::little_endian> C;
C c;
char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -299,7 +299,7 @@ void TestHelper<CharT, 4>::test() {
assert(r == 2);
}
{
- typedef std::codecvt_utf16<char32_t, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
+ typedef std::codecvt_utf16<CharT, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
C c;
char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
std::mbstate_t m;
@@ -324,7 +324,9 @@ void TestHelper<CharT, 4>::test() {
}
int main(int, char**) {
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
TestHelper<wchar_t>::test();
+#endif
TestHelper<char16_t>::test();
TestHelper<char32_t>::test();
return 0;
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp
index f644b11db05cd79..3e84aa02b24e3da 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp
@@ -68,7 +68,7 @@ constexpr void test() {
// Contraint failure
test_constraint_fail<bool>();
test_constraint_fail<char>();
-#ifndef TEST_HAS_NO_INT128
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test_constraint_fail<wchar_t>();
#endif
test_constraint_fail<char8_t>();
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp
index 9676d29b2c32cd2..7fa8c7ab9acbeb0 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp
@@ -65,7 +65,7 @@ constexpr void test() {
// Contraint failure
test_constraint_fail<bool>();
test_constraint_fail<char>();
-#ifndef TEST_HAS_NO_INT128
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test_constraint_fail<wchar_t>();
#endif
test_constraint_fail<char8_t>();
diff --git a/libcxx/test/std/re/re.iter/re.tokiter/types.pass.cpp b/libcxx/test/std/re/re.iter/re.tokiter/types.pass.cpp
index a9c18e8a1b77a16..dc879cae39f2bc3 100644
--- a/libcxx/test/std/re/re.iter/re.tokiter/types.pass.cpp
+++ b/libcxx/test/std/re/re.iter/re.tokiter/types.pass.cpp
@@ -45,7 +45,9 @@ test()
int main(int, char**)
{
test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/re/re.regex/re.regex.const/constants.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.const/constants.pass.cpp
index 5d8d48d0590da35..fab3d7f9fd384b1 100644
--- a/libcxx/test/std/re/re.regex/re.regex.const/constants.pass.cpp
+++ b/libcxx/test/std/re/re.regex/re.regex.const/constants.pass.cpp
@@ -61,7 +61,9 @@ test()
int main(int, char**)
{
test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/re/re.regex/types.pass.cpp b/libcxx/test/std/re/re.regex/types.pass.cpp
index a13ad180d3cb420..80ee654c9b93779 100644
--- a/libcxx/test/std/re/re.regex/types.pass.cpp
+++ b/libcxx/test/std/re/re.regex/types.pass.cpp
@@ -32,12 +32,14 @@ int main(int, char**)
std::regex_constants::syntax_option_type>::value), "");
static_assert((std::is_same<std::basic_regex<char>::locale_type, std::locale>::value), "");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
static_assert((std::is_same<std::basic_regex<wchar_t>::value_type, wchar_t>::value), "");
static_assert((std::is_same<std::basic_regex<wchar_t>::traits_type, std::regex_traits<wchar_t> >::value), "");
static_assert((std::is_same<std::basic_regex<wchar_t>::string_type, std::basic_string<wchar_t> >::value), "");
static_assert((std::is_same<std::basic_regex<wchar_t>::flag_type,
std::regex_constants::syntax_option_type>::value), "");
static_assert((std::is_same<std::basic_regex<wchar_t>::locale_type, std::locale>::value), "");
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/re/re.results/re.results.size/max_size.pass.cpp b/libcxx/test/std/re/re.results/re.results.size/max_size.pass.cpp
index 184933d135c76ce..73841b33990832e 100644
--- a/libcxx/test/std/re/re.results/re.results.size/max_size.pass.cpp
+++ b/libcxx/test/std/re/re.results/re.results.size/max_size.pass.cpp
@@ -27,7 +27,9 @@ test()
int main(int, char**)
{
test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/re/re.results/types.pass.cpp b/libcxx/test/std/re/re.results/types.pass.cpp
index 0fd8220843b171f..722eb3e294e4863 100644
--- a/libcxx/test/std/re/re.results/types.pass.cpp
+++ b/libcxx/test/std/re/re.results/types.pass.cpp
@@ -47,7 +47,9 @@ test()
int main(int, char**)
{
test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/strings/string.view/enable_borrowed_range.compile.pass.cpp b/libcxx/test/std/strings/string.view/enable_borrowed_range.compile.pass.cpp
index 12f7d0fb0c070a5..39e9c6d0c8a9eb4 100644
--- a/libcxx/test/std/strings/string.view/enable_borrowed_range.compile.pass.cpp
+++ b/libcxx/test/std/strings/string.view/enable_borrowed_range.compile.pass.cpp
@@ -21,6 +21,10 @@
void test() {
using std::ranges::enable_borrowed_range;
static_assert(enable_borrowed_range<std::basic_string_view<char> >);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
static_assert(enable_borrowed_range<std::basic_string_view<wchar_t> >);
+#endif
+#ifndef TEST_HAS_NO_CHAR8_T
static_assert(enable_borrowed_range<std::basic_string_view<char8_t> >);
+#endif
}
More information about the libcxx-commits
mailing list