[libc++][NFC] Add missing conditionals for the existence of wide characters
authorLouis Dionne <ldionne.2@gmail.com>
Mon, 21 Nov 2022 14:50:31 +0000 (09:50 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Mon, 21 Nov 2022 23:00:53 +0000 (18:00 -0500)
Differential Revision: https://reviews.llvm.org/D138435

30 files changed:
libcxx/include/locale
libcxx/include/streambuf
libcxx/test/libcxx/input.output/file.streams/fstreams/filebuf/traits_mismatch.fail.cpp
libcxx/test/libcxx/input.output/file.streams/fstreams/traits_mismatch.fail.cpp
libcxx/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.h
libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp
libcxx/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
libcxx/test/std/strings/basic.string/traits_mismatch.verify.cpp
libcxx/test/std/strings/basic.string/types.pass.cpp
libcxx/test/std/strings/string.view/string.view.access/at.pass.cpp
libcxx/test/std/strings/string.view/string.view.access/back.pass.cpp
libcxx/test/std/strings/string.view/string.view.access/data.pass.cpp
libcxx/test/std/strings/string.view/string.view.access/front.pass.cpp
libcxx/test/std/strings/string.view/string.view.access/index.pass.cpp
libcxx/test/std/strings/string.view/string.view.cons/from_literal.pass.cpp
libcxx/test/std/strings/string.view/string.view.cons/from_ptr_len.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.pointer.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/compare.sv.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
libcxx/test/std/strings/string.view/string.view.ops/substr.pass.cpp
libcxx/test/std/strings/string.view/types.pass.cpp
libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp
libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/begin.pass.cpp
libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/ctor.pass.cpp
libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/end.pass.cpp
libcxx/utils/generate_extended_grapheme_cluster_test.py

index 8a330ae..015efd8 100644 (file)
@@ -2385,7 +2385,9 @@ extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_
 /**/
 
 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
+#endif
 #undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
@@ -2445,8 +2447,10 @@ protected:
     ~__time_put();
     void __do_put(char* __nb, char*& __ne, const tm* __tm,
                   char __fmt, char __mod) const;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
                   char __fmt, char __mod) const;
+#endif
 };
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
index 53a7172..d473df1 100644 (file)
@@ -489,10 +489,12 @@ basic_streambuf<_CharT, _Traits>::overflow(int_type)
 }
 
 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
-extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
-
 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
index c607c63..27871b0 100644 (file)
@@ -13,6 +13,8 @@
 //
 // The char type of the stream and the char_type of the traits have to match
 
+// UNSUPPORTED: no-wide-characters
+
 #include <fstream>
 
 int main(int, char**)
index 545530b..ce22fee 100644 (file)
@@ -13,6 +13,8 @@
 
 // The char type of the stream and the char_type of the traits have to match
 
+// UNSUPPORTED: no-wide-characters
+
 #include <fstream>
 
 int main(int, char**)
index e66d4b1..f281222 100644 (file)
@@ -65,6 +65,8 @@
 #include <string_view>
 #include <vector>
 
+#include "test_macros.h"
+
 template <class CharT>
 struct data {
   /// The input to parse.
@@ -689,6 +691,7 @@ std::array<data<char>, 602> data_utf8 = {{
 /// Note that most of the data for the UTF-16 and UTF-32 are identical. However
 /// since the size of the code units differ the breaks can contain different
 /// values.
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
 std::array<data<wchar_t>, 602> data_utf16 = {{
      {L"\U00000020\U00000020", {32, 32}, {1, 2}},
      {L"\U00000020\U00000308\U00000020", {32, 32}, {2, 3}},
@@ -1901,5 +1904,6 @@ std::array<data<wchar_t>, 602> data_utf32 = {{
      {L"\U00000061\U0000200d\U0001f6d1", {97, 128721}, {2, 3}},
      {L"\U00002701\U0000200d\U00002701", {9985}, {3}},
      {L"\U00000061\U0000200d\U00002701", {97, 9985}, {2, 3}}}};
+#endif // TEST_HAS_NO_WIDE_CHARACTERS
 
 #endif // LIBCXX_TEST_STD_UTILITIES_FORMAT_FORMAT_STRING_FORMAT_STRING_STD_EXTENDED_GRAPHEME_CLUSTER_H
index bb70095..4a028fc 100644 (file)
@@ -28,7 +28,9 @@ test()
 int main(int, char**)
 {
     test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test<wchar_t>();
+#endif
 
-  return 0;
+    return 0;
 }
index 72604a7..d6db253 100644 (file)
@@ -44,10 +44,13 @@ struct CanDeduce<Iter, Alloc, decltype((void)
   std::basic_string{std::declval<Iter>(), std::declval<Iter>(), std::declval<Alloc>()}
 )> : std::true_type { };
 
-static_assert( CanDeduce<int*, std::allocator<int>>::value);
+static_assert( CanDeduce<char*, std::allocator<char>>::value);
 static_assert(!CanDeduce<NotAnIterator, std::allocator<char>>::value);
 static_assert(!CanDeduce<NotAnInputIterator, std::allocator<char16_t>>::value);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert( CanDeduce<wchar_t*, std::allocator<wchar_t>>::value);
 static_assert(!CanDeduce<wchar_t const*, NotAnAllocator<wchar_t>>::value);
+#endif
 
 TEST_CONSTEXPR_CXX20 bool test() {
   {
@@ -70,6 +73,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
     assert(s1.size() == 10);
     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
   }
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   {
     const wchar_t* s = L"12345678901234";
     std::basic_string s1{s, s+10, test_allocator<wchar_t>{}};
@@ -80,6 +84,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
     assert(s1.size() == 10);
     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
   }
+#endif
   {
     const char16_t* s = u"12345678901234";
     std::basic_string s1{s, s+10, min_allocator<char16_t>{}};
index 6730e2f..82c438b 100644 (file)
@@ -9,6 +9,8 @@
 // <string>
 //   The strings's value type must be the same as the traits's char_type
 
+// UNSUPPORTED: no-wide-characters
+
 #include <string>
 
 std::basic_string<char, std::char_traits<wchar_t> > s; // expected-error@*:* {{traits_type::char_type must be the same type as CharT}}
index 910b336..542336b 100644 (file)
@@ -74,7 +74,9 @@ test()
 int main(int, char**)
 {
     test<test_traits<char>, test_allocator<char> >();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test<std::char_traits<wchar_t>, std::allocator<wchar_t> >();
+#endif
     static_assert((std::is_same<std::basic_string<char>::traits_type,
                                 std::char_traits<char> >::value), "");
     static_assert((std::is_same<std::basic_string<char>::allocator_type,
index 82da10d..99a81ac 100644 (file)
@@ -35,8 +35,10 @@ int main(int, char**) {
     test ( "ABCDE", 5 );
     test ( "a", 1 );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"ABCDE", 5 );
     test ( L"a", 1 );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"ABCDE", 5 );
index d5a21bb..49b84ab 100644 (file)
@@ -32,8 +32,10 @@ int main(int, char**) {
     assert ( test ( "ABCDE", 5 ));
     assert ( test ( "a", 1 ));
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     assert ( test ( L"ABCDE", 5 ));
     assert ( test ( L"a", 1 ));
+#endif
 
 #if TEST_STD_VER >= 11
     assert ( test ( u"ABCDE", 5 ));
index 1c8540a..50d2a14 100644 (file)
@@ -33,8 +33,10 @@ int main(int, char**) {
     test ( "ABCDE", 5 );
     test ( "a", 1 );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"ABCDE", 5 );
     test ( L"a", 1 );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"ABCDE", 5 );
index 900a698..d9e1607 100644 (file)
@@ -32,8 +32,10 @@ int main(int, char**) {
     assert ( test ( "ABCDE", 5 ));
     assert ( test ( "a", 1 ));
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     assert ( test ( L"ABCDE", 5 ));
     assert ( test ( L"a", 1 ));
+#endif
 
 #if TEST_STD_VER >= 11
     assert ( test ( u"ABCDE", 5 ));
index 493787a..b27bc65 100644 (file)
@@ -34,8 +34,10 @@ int main(int, char**) {
     test ( "ABCDE", 5 );
     test ( "a", 1 );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"ABCDE", 5 );
     test ( L"a", 1 );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"ABCDE", 5 );
index b58a838..124aaea 100644 (file)
@@ -45,9 +45,11 @@ int main(int, char**) {
     test ( "A" );
     test ( "" );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"QBCDE" );
     test ( L"A" );
     test ( L"" );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"QBCDE" );
index 540fa74..8d48f90 100644 (file)
@@ -45,6 +45,7 @@ int main(int, char**) {
     }
 #endif
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"QBCDE", 5 );
     test ( L"QBCDE", 2 );
     test ( L"", 0 );
@@ -56,6 +57,7 @@ int main(int, char**) {
     static_assert ( sv1.data() == s, "" );
     }
 #endif
+#endif // TEST_HAS_NO_WIDE_CHARACTERS
 
 #if TEST_STD_VER >= 11
     test ( u"QBCDE", 5 );
index 3133939..ed06bec 100644 (file)
@@ -55,6 +55,7 @@ int main(int, char**)
     test("abcdefghijklmnopqrst", "abcdefghijklmnopqrst", 0);
     }
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     {
     test(L"", L"", 0);
     test(L"", L"abcde", -5);
@@ -73,6 +74,7 @@ int main(int, char**)
     test(L"abcdefghijklmnopqrst", L"abcdefghij", 10);
     test(L"abcdefghijklmnopqrst", L"abcdefghijklmnopqrst", 0);
     }
+#endif
 
 #if TEST_STD_VER >= 11
     {
index d21a0c5..a7a5c30 100644 (file)
@@ -381,6 +381,7 @@ int main(int, char**)
     test("abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), "abcdefghijklmnopqrst", 0);
     }
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     {
     test(L"", 0, 0, L"", 0);
     test(L"", 0, 0, L"abcde", -5);
@@ -399,6 +400,7 @@ int main(int, char**)
     test(L"abcdefghijklmnopqrst", 0, 12, L"abcdefghij", 10);
     test(L"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), L"abcdefghijklmnopqrst", 0);
     }
+#endif
 
 #if TEST_STD_VER >= 11
     {
index e4dd2c5..477bfdd 100644 (file)
@@ -368,12 +368,14 @@ int main(int, char**) {
     test("ABCde", 2, 4, "abcde", -1);
     }
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     {
     test(L"abcde", 5, 1, L"", 0);
     test(L"abcde", 2, 4, L"", 3);
     test(L"abcde", 2, 4, L"abcde", 2);
     test(L"ABCde", 2, 4, L"abcde", -1);
     }
+#endif
 
 #if TEST_STD_VER >= 11
     {
index 57a0b13..f0c4a79 100644 (file)
@@ -1315,6 +1315,7 @@ int main(int, char**) {
     test("abcdefghijklmnopqrst", 10, 0, "abcdefghij", 10, -10);
     }
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     {
     test(L"", 0, 0, L"abcde", 0, 0);
     test(L"", 0, 0, L"abcde", 1, -1);
@@ -1322,6 +1323,7 @@ int main(int, char**) {
     test(L"abcdefghijklmnopqrst", 21, 0, L"abcde", 1, 0);
     test(L"abcdefghijklmnopqrst", 10, 0, L"abcdefghij", 10, -10);
     }
+#endif
 
 #if TEST_STD_VER >= 11
     {
index 3ea44ae..a0f661c 100644 (file)
@@ -5814,12 +5814,14 @@ int main(int, char**) {
     test("ABCde", 2, 4, "abcde", 2, 4, -1);
     }
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     {
     test(L"abcde", 5, 1, L"", 0, 0, 0);
     test(L"abcde", 2, 4, L"", 0, 0, 3);
     test(L"abcde", 2, 4, L"abcde", 3, 4, -2);
     test(L"ABCde", 2, 4, L"abcde", 2, 4, -1);
     }
+#endif
 
 #if TEST_STD_VER >= 11
     {
index ff68706..7db327d 100644 (file)
@@ -55,6 +55,7 @@ int main(int, char**) {
     test("abcdefghijklmnopqrst", "abcdefghij", 10);
     test("abcdefghijklmnopqrst", "abcdefghijklmnopqrst", 0);
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test(L"",                     L"", 0);
     test(L"",                     L"abcde", -5);
     test(L"",                     L"abcdefghij", -10);
@@ -71,6 +72,7 @@ int main(int, char**) {
     test(L"abcdefghijklmnopqrst", L"abcde", 15);
     test(L"abcdefghijklmnopqrst", L"abcdefghij", 10);
     test(L"abcdefghijklmnopqrst", L"abcdefghijklmnopqrst", 0);
+#endif
 
 #if TEST_STD_VER >= 11
     test(u"",                     u"", 0);
index 709e265..54e185f 100644 (file)
@@ -93,10 +93,12 @@ int main(int, char**) {
     test ( "a" );
     test ( "" );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
     test ( L"ABCDE" );
     test ( L"a" );
     test ( L"" );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
@@ -111,7 +113,9 @@ int main(int, char**) {
 #endif
 
     test_constexpr_copy("ABCDE", "GHIJK", "BCDJK");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test_constexpr_copy(L"ABCDE", L"GHIJK", L"BCDJK");
+#endif
 #if TEST_STD_VER >= 11
     test_constexpr_copy(u"ABCDE", u"GHIJK", u"BCDJK");
     test_constexpr_copy(U"ABCDE", U"GHIJK", U"BCDJK");
@@ -121,7 +125,9 @@ int main(int, char**) {
 #endif
 #if TEST_STD_VER >= 20
     static_assert(test_constexpr_copy("ABCDE", "GHIJK", "BCDJK"));
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     static_assert(test_constexpr_copy(L"ABCDE", L"GHIJK", L"BCDJK"));
+#endif
     static_assert(test_constexpr_copy(u"ABCDE", u"GHIJK", u"BCDJK"));
     static_assert(test_constexpr_copy(U"ABCDE", U"GHIJK", U"BCDJK"));
     static_assert(test_constexpr_copy(u8"ABCDE", u8"GHIJK", u8"BCDJK"));
index c2b9511..92f9d8c 100644 (file)
@@ -77,10 +77,12 @@ int main(int, char**) {
     test ( "a" );
     test ( "" );
 
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
     test ( L"ABCDE" );
     test ( L"a" );
     test ( L"" );
+#endif
 
 #if TEST_STD_VER >= 11
     test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
index e9d3d24..f952f20 100644 (file)
@@ -72,7 +72,9 @@ test()
 int main(int, char**)
 {
     test<std::char_traits<char> >();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test<std::char_traits<wchar_t> >();
+#endif
 #ifndef TEST_HAS_NO_CHAR8_T
     test<std::char_traits<char8_t> >();
 #endif
index 6b4afcb..1a69942 100644 (file)
@@ -50,7 +50,9 @@ constexpr void test(const CharT* fmt) {
 
 constexpr bool test() {
   test("abc");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test(L"abc");
+#endif
 #ifndef TEST_HAS_NO_CHAR8_T
   test(u8"abc");
 #endif
index 63122dc..df3563e 100644 (file)
@@ -36,7 +36,9 @@ constexpr void test(const CharT* fmt) {
 
 constexpr bool test() {
   test("abc");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test(L"abc");
+#endif
 #ifndef TEST_HAS_NO_CHAR8_T
   test(u8"abc");
 #endif
index 08cd9d5..8b1601e 100644 (file)
@@ -57,7 +57,9 @@ constexpr void test(const CharT* fmt) {
 
 constexpr bool test() {
   test("abc");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test(L"abc");
+#endif
 #ifndef TEST_HAS_NO_CHAR8_T
   test(u8"abc");
 #endif
index e135418..e1d0f2f 100644 (file)
@@ -36,7 +36,9 @@ constexpr void test(const CharT* fmt) {
 
 constexpr bool test() {
   test("abc");
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test(L"abc");
+#endif
 #ifndef TEST_HAS_NO_CHAR8_T
   test(u8"abc");
 #endif
index c263cdd..5061c80 100755 (executable)
@@ -156,6 +156,8 @@ cpp_template = """// -*- C++ -*-
 #include <string_view>
 #include <vector>
 
+#include "test_macros.h"
+
 template <class CharT>
 struct data {{
   /// The input to parse.
@@ -179,6 +181,7 @@ std::array<data<char>, {0}> data_utf8 = {{{{
 /// Note that most of the data for the UTF-16 and UTF-32 are identical. However
 /// since the size of the code units differ the breaks can contain different
 /// values.
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
 std::array<data<wchar_t>, {0}> data_utf16 = {{{{
 {2}}}}};
 
@@ -189,6 +192,7 @@ std::array<data<wchar_t>, {0}> data_utf16 = {{{{
 /// values.
 std::array<data<wchar_t>, {0}> data_utf32 = {{{{
 {3}}}}};
+#endif // TEST_HAS_NO_WIDE_CHARACTERS
 
 #endif // LIBCXX_TEST_STD_UTILITIES_FORMAT_FORMAT_STRING_FORMAT_STRING_STD_EXTENDED_GRAPHEME_CLUSTER_H"""