[libcxx-commits] [libcxx] [libc++] Properly define _LIBCPP_HAS_NO_UNICODE in __config_site (PR #95138)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 18 05:59:21 PDT 2024


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

>From b4d384046b7f175ea3363e35fb4c728e155a3d7f Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 11 Jun 2024 12:23:16 -0400
Subject: [PATCH 1/3] [libc++] Properly define _LIBCPP_HAS_NO_UNICODE in
 __config_site

Fixes #93638
---
 libcxx/include/__config_site.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 89a14609ee3f9..67022146c9082 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -26,6 +26,7 @@
 #cmakedefine _LIBCPP_HAS_NO_FILESYSTEM
 #cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE
 #cmakedefine _LIBCPP_HAS_NO_LOCALIZATION
+#cmakedefine _LIBCPP_HAS_NO_UNICODE
 #cmakedefine _LIBCPP_HAS_NO_WIDE_CHARACTERS
 #cmakedefine _LIBCPP_HAS_NO_STD_MODULES
 #cmakedefine _LIBCPP_HAS_NO_TIME_ZONE_DATABASE

>From fb7c87c9b87c56e74779b17cd452ae9b13f210f3 Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Sat, 15 Jun 2024 16:22:35 +0200
Subject: [PATCH 2/3] Fixes most compilation issues.

Two test still fail but need a bit more investigation.
---
 libcxx/include/__format/parser_std_format_spec.h          | 4 ++--
 .../ostream.formatted.print/vprint_unicode.pass.cpp       | 1 +
 .../iostream.format/print.fun/transcoding.pass.cpp        | 1 +
 .../print.fun/vprint_unicode_posix.pass.cpp               | 1 +
 .../print.fun/vprint_unicode_windows.pass.cpp             | 1 +
 .../utilities/format/format.functions/ascii.pass.cpp      | 1 +
 .../format/format.functions/escaped_output.ascii.pass.cpp | 1 +
 .../format.string.std/extended_grapheme_cluster.pass.cpp  | 1 +
 .../ostream.formatted.print/locale-specific_form.pass.cpp | 2 ++
 .../ostream.formatted.print/vprint_unicode.pass.cpp       | 1 +
 .../print.fun/no_file_description.pass.cpp                | 2 ++
 .../iostream.format/print.fun/vprint_unicode.sh.cpp       | 1 +
 .../formatter.char.fsigned-char.pass.cpp                  | 8 +++++---
 .../formatter.char.funsigned-char.pass.cpp                | 2 +-
 14 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__format/parser_std_format_spec.h b/libcxx/include/__format/parser_std_format_spec.h
index 9818f37b518e8..150bdde89f3b3 100644
--- a/libcxx/include/__format/parser_std_format_spec.h
+++ b/libcxx/include/__format/parser_std_format_spec.h
@@ -1155,8 +1155,8 @@ __estimate_column_width(basic_string_view<_CharT> __str, size_t __maximum, __col
   // When Unicode isn't supported assume ASCII and every code unit is one code
   // point. In ASCII the estimated column width is always one. Thus there's no
   // need for rounding.
-  size_t __width_ = std::min(__str.size(), __maximum);
-  return {__width_, __str.begin() + __width_};
+  size_t __width = std::min(__str.size(), __maximum);
+  return {__width, __str.begin() + __width};
 }
 
 #  endif // !defined(_LIBCPP_HAS_NO_UNICODE)
diff --git a/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
index 572c6ca474014..9c801f5e044c1 100644
--- a/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
+++ b/libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 // UNSUPPORTED: no-filesystem, no-rtti
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // XFAIL: availability-fp_to_chars-missing
diff --git a/libcxx/test/libcxx/input.output/iostream.format/print.fun/transcoding.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/print.fun/transcoding.pass.cpp
index 168fa40a243c5..ab524899e28a2 100644
--- a/libcxx/test/libcxx/input.output/iostream.format/print.fun/transcoding.pass.cpp
+++ b/libcxx/test/libcxx/input.output/iostream.format/print.fun/transcoding.pass.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 // UNSUPPORTED: no-filesystem
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 // ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=2000000
 
diff --git a/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_posix.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_posix.pass.cpp
index 9a50770d97dbc..fd570c2c76619 100644
--- a/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_posix.pass.cpp
+++ b/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_posix.pass.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 // UNSUPPORTED: no-filesystem
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // XFAIL: availability-fp_to_chars-missing
diff --git a/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_windows.pass.cpp b/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_windows.pass.cpp
index 2dd76052c2c97..7d17662da28fa 100644
--- a/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_windows.pass.cpp
+++ b/libcxx/test/libcxx/input.output/iostream.format/print.fun/vprint_unicode_windows.pass.cpp
@@ -8,6 +8,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 // UNSUPPORTED: no-filesystem
 // UNSUPPORTED: no-wide-characters
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // Clang modules do not work with the definiton of _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION
diff --git a/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp b/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
index d4a55dd20ce98..689ebd15a964b 100644
--- a/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
@@ -8,6 +8,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
+// What would be the best way to force the test with unicode disabled?
 // Force unicode to be disabled.
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_HAS_NO_UNICODE
 
diff --git a/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp b/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
index 32352774a08f9..bb3c771d0419e 100644
--- a/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
@@ -11,6 +11,7 @@
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
 
+// What would be the best way to force the test with unicode disabled?
 // Force unicode to be disabled.
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_HAS_NO_UNICODE
 
diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.pass.cpp
index c1fdd1f2098d2..f69a995dc1784 100644
--- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.pass.cpp
@@ -6,6 +6,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // <format>
diff --git a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp
index 2e19e38e2ed04..57023b73c4744 100644
--- a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp
@@ -66,6 +66,7 @@ test(std::stringstream& stream, std::string expected, test_format_string<char, A
                      "\nFormat string   ", fmt.get(), "\nExpected output ", expected, "\nActual output   ", out, '\n'));
   }
   // *** vprint_unicode ***
+#ifndef TEST_HAS_NO_UNICODE
   {
     stream.str("");
 
@@ -75,6 +76,7 @@ test(std::stringstream& stream, std::string expected, test_format_string<char, A
                  TEST_WRITE_CONCATENATED(
                      "\nFormat string   ", fmt.get(), "\nExpected output ", expected, "\nActual output   ", out, '\n'));
   }
+#endif // TEST_HAS_NO_UNICODE
   // *** vprint_nonunicode ***
   {
     stream.str("");
diff --git a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
index b04a745b348f5..b4d6b3529cec4 100644
--- a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
@@ -6,6 +6,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // TODO PRINT Investigate see https://reviews.llvm.org/D156585
diff --git a/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
index ffa48c5e745d6..70e0c11c5e6c5 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
@@ -80,6 +80,7 @@ static void test_println_blank_line() {
 }
 
 static void test_vprint_unicode() {
+#ifdef TEST_HAS_NO_UNICODE
   std::array<char, 100> buffer{0};
 
   FILE* file = fmemopen(buffer.data(), buffer.size(), "wb");
@@ -92,6 +93,7 @@ static void test_vprint_unicode() {
 
   assert(pos > 0);
   assert(std::string_view(buffer.data(), pos) == "hello world!");
+#endif // TEST_HAS_NO_UNICODE
 }
 
 static void test_vprint_nonunicode() {
diff --git a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.sh.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.sh.cpp
index 198e71b55d9be..e32a794b96dd9 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.sh.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 // UNSUPPORTED: no-filesystem
+// UNSUPPORTED: libcpp-has-no-unicode
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // XFAIL: availability-fp_to_chars-missing
diff --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.fsigned-char.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.fsigned-char.pass.cpp
index d0da8d69f3f99..f3d587e11f255 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.fsigned-char.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.fsigned-char.pass.cpp
@@ -71,17 +71,19 @@ void test() {
 #if TEST_STD_VER > 20
   test(STR(R"('\u{0}')"), STR("?}"), '\x00');
   test(STR("'a'"), STR("?}"), 'a');
+#  ifndef TEST_HAS_NO_UNICODE
   if constexpr (std::same_as<CharT, char>) {
     test(STR(R"('\x{80}')"), STR("?}"), '\x80');
     test(STR(R"('\x{ff}')"), STR("?}"), '\xff');
   }
-#  ifndef TEST_HAS_NO_WIDE_CHARACTERS
+#    ifndef TEST_HAS_NO_WIDE_CHARACTERS
   else {
     test(STR(R"('\u{80}')"), STR("?}"), '\x80');
     test(STR("'\u00ff'"), STR("?}"), '\xff');
   }
-#  endif // TEST_HAS_NO_WIDE_CHARACTERS
-#endif   // TEST_STD_VER > 20
+#    endif // TEST_HAS_NO_WIDE_CHARACTERS
+#  endif   // TEST_HAS_NO_UNICODE
+#endif     // TEST_STD_VER > 20
 
   test(STR("10000000"), STR("b}"), char(-128));
   test(STR("11111111"), STR("b}"), char(-1));
diff --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.funsigned-char.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.funsigned-char.pass.cpp
index a7577c1bd9341..230fe7f55808d 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.funsigned-char.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.funsigned-char.pass.cpp
@@ -83,7 +83,7 @@ void test() {
   }
 #    endif // TEST_HAS_NO_WIDE_CHARACTERS
 #  endif   // TEST_HAS_NO_UNICODE
-#endif   // TEST_STD_VER > 20
+#endif     // TEST_STD_VER > 20
 
   test(STR("10000000"), STR("b}"), char(128));
   test(STR("11111111"), STR("b}"), char(255));

>From b45a16650d1a8c47a1ebc7e2492a8527bb4f429a Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 18 Jun 2024 08:58:35 -0400
Subject: [PATCH 3/3] REQUIRES in ASCII test

---
 .../libcxx/utilities/format/format.functions/ascii.pass.cpp   | 4 +---
 .../format/format.functions/escaped_output.ascii.pass.cpp     | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp b/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
index 689ebd15a964b..dd6b36eb13152 100644
--- a/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/format.functions/ascii.pass.cpp
@@ -8,9 +8,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
-// What would be the best way to force the test with unicode disabled?
-// Force unicode to be disabled.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_HAS_NO_UNICODE
+// REQUIRES: libcpp-has-no-unicode
 
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
diff --git a/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp b/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
index bb3c771d0419e..d43d4de04b842 100644
--- a/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/format.functions/escaped_output.ascii.pass.cpp
@@ -11,9 +11,7 @@
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
 
-// What would be the best way to force the test with unicode disabled?
-// Force unicode to be disabled.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_HAS_NO_UNICODE
+// REQUIRES: libcpp-has-no-unicode
 
 // <format>
 



More information about the libcxx-commits mailing list