[libcxx-commits] [libcxx] [libc++] Guard unchecked uses of wchar_t and char8_t in tests (PR #229255)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 5 15:50:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Louis Dionne (ldionne)
<details>
<summary>Changes</summary>
A few places in the test suite were not properly guarding based on whether wide characters or char8_t are available.
---
Full diff: https://github.com/llvm/llvm-project/pull/229255.diff
14 Files Affected:
- (modified) libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp (+2)
- (modified) libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h (+1-1)
- (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/types.pass.cpp (+6-3)
- (modified) libcxx/test/std/localization/locale.categories/category.time/locale.time.get/types.pass.cpp (+7-4)
- (modified) libcxx/test/std/localization/locale.categories/category.time/locale.time.put/types.pass.cpp (+6-3)
- (modified) libcxx/test/std/localization/locale.stdcvt/codecvt_utf16_length.pass.cpp (+14-12)
- (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp (+1-1)
- (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp (+1-1)
- (modified) libcxx/test/std/re/re.iter/re.tokiter/types.pass.cpp (+3-1)
- (modified) libcxx/test/std/re/re.regex/re.regex.const/constants.pass.cpp (+3-1)
- (modified) libcxx/test/std/re/re.regex/types.pass.cpp (+3-1)
- (modified) libcxx/test/std/re/re.results/re.results.size/max_size.pass.cpp (+3-1)
- (modified) libcxx/test/std/re/re.results/types.pass.cpp (+3-1)
- (modified) libcxx/test/std/strings/string.view/enable_borrowed_range.compile.pass.cpp (+4)
``````````diff
diff --git a/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp b/libcxx/test/libcxx/algorithms/specialized_algorithms.compile.pass.cpp
index 22e44f897d57f..8d4ff6304f8a1 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 eb4b7a1d2e62f..51d6ec3c47836 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 ea9ea9fcf0b60..c1e0fe4a74582 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 8d8889551444d..84cff8592030c 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 8a661a78cb129..07249639340e3 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 68898957599f3..b52db432240b8 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 f644b11db05cd..3e84aa02b24e3 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 9676d29b2c32c..7fa8c7ab9acbe 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 a9c18e8a1b77a..dc879cae39f2b 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 5d8d48d0590da..fab3d7f9fd384 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 a13ad180d3cb4..80ee654c9b937 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 184933d135c76..73841b3399083 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 0fd8220843b17..722eb3e294e48 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 12f7d0fb0c070..39e9c6d0c8a9e 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
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/229255
More information about the libcxx-commits
mailing list