Adjust C++11/C++14 tests to work with -fchar8_t
authorJonathan Wakely <jwakely@redhat.com>
Tue, 19 Feb 2019 02:55:12 +0000 (02:55 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 19 Feb 2019 02:55:12 +0000 (02:55 +0000)
* testsuite/21_strings/basic_string/literals/types.cc
[_GLIBCXX_USE_CHAR8_T]: Adjust expected string type for u8 literal.
* testsuite/21_strings/basic_string/literals/values.cc
[_GLIBCXX_USE_CHAR8_T]: Likewise.
* testsuite/22_locale/codecvt/char16_t.cc: Adjust for u8 literals
potentially having different type.
* testsuite/22_locale/codecvt/char32_t.cc: Likewise.
* testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Cast u8 literal
to char.
* testsuite/22_locale/codecvt/codecvt_utf8/wchar_t/1.cc: Likewise.
* testsuite/22_locale/codecvt/utf8.cc: Likewise.
* testsuite/22_locale/conversions/string/2.cc: Remove u8 prefix from
string literals only using basic character set.
* testsuite/22_locale/conversions/string/3.cc: Likewise. Cast other
u8 literals to char.
* testsuite/29_atomics/headers/atomic/macros.cc [_GLIBCXX_USE_CHAR8_T]:
Test ATOMIC_CHAR8_T_LOCK_FREE.
Add missing #error to ATOMIC_CHAR16_T_LOCK_FREE test.
* testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
[_GLIBCXX_USE_CHAR8_T]: Check for std::atomic_char8_t.
* testsuite/experimental/string_view/literals/types.cc
[_GLIBCXX_USE_CHAR8_T]: Adjust expected string_view type for u8
literal.
* testsuite/experimental/string_view/literals/values.cc
[_GLIBCXX_USE_CHAR8_T]: Likewise.

From-SVN: r269006

16 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/21_strings/basic_string/literals/types.cc
libstdc++-v3/testsuite/21_strings/basic_string/literals/values.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc
libstdc++-v3/testsuite/22_locale/codecvt/char16_t.cc
libstdc++-v3/testsuite/22_locale/codecvt/char32_t.cc
libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/wchar_t/1.cc
libstdc++-v3/testsuite/22_locale/codecvt/utf8.cc
libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
libstdc++-v3/testsuite/29_atomics/headers/atomic/macros.cc
libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
libstdc++-v3/testsuite/experimental/string_view/literals/types.cc
libstdc++-v3/testsuite/experimental/string_view/literals/values.cc

index fd9ad8f..99108d9 100644 (file)
@@ -1,3 +1,31 @@
+2019-02-19  Jonathan Wakely  <jwakely@redhat.com>
+
+       * testsuite/21_strings/basic_string/literals/types.cc
+       [_GLIBCXX_USE_CHAR8_T]: Adjust expected string type for u8 literal.
+       * testsuite/21_strings/basic_string/literals/values.cc
+       [_GLIBCXX_USE_CHAR8_T]: Likewise.
+       * testsuite/22_locale/codecvt/char16_t.cc: Adjust for u8 literals
+       potentially having different type.
+       * testsuite/22_locale/codecvt/char32_t.cc: Likewise.
+       * testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Cast u8 literal
+       to char.
+       * testsuite/22_locale/codecvt/codecvt_utf8/wchar_t/1.cc: Likewise.
+       * testsuite/22_locale/codecvt/utf8.cc: Likewise.
+       * testsuite/22_locale/conversions/string/2.cc: Remove u8 prefix from
+       string literals only using basic character set.
+       * testsuite/22_locale/conversions/string/3.cc: Likewise. Cast other
+       u8 literals to char.
+       * testsuite/29_atomics/headers/atomic/macros.cc [_GLIBCXX_USE_CHAR8_T]:
+       Test ATOMIC_CHAR8_T_LOCK_FREE.
+       Add missing #error to ATOMIC_CHAR16_T_LOCK_FREE test.
+       * testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
+       [_GLIBCXX_USE_CHAR8_T]: Check for std::atomic_char8_t.
+       * testsuite/experimental/string_view/literals/types.cc
+       [_GLIBCXX_USE_CHAR8_T]: Adjust expected string_view type for u8
+       literal.
+       * testsuite/experimental/string_view/literals/values.cc
+       [_GLIBCXX_USE_CHAR8_T]: Likewise.
+
 2019-02-19  Tom Honermann  <tom@honermann.net>
 
        * testsuite/18_support/numeric_limits/char8_t.cc: New test cloned
index aa103ba..1dbd70a 100644 (file)
 #include <string>
 #include <type_traits>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::u8string;
+#else
+using u8string = std::string;
+#endif
+
 void
 test01()
 {
@@ -28,7 +34,7 @@ test01()
   static_assert(std::is_same<decltype("Hello"s), std::string>::value,
                "\"Hello\"s is std::string");
 
-  static_assert(std::is_same<decltype(u8"Hello"s), std::string>::value,
+  static_assert(std::is_same<decltype(u8"Hello"s), u8string>::value,
                "u8\"Hello\"s is std::string");
 
 #ifdef _GLIBCXX_USE_WCHAR_T
index 8b0741d..f0d48c8 100644 (file)
 #include <string>
 #include <testsuite_hooks.h>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::u8string;
+#else
+using u8string = std::string;
+#endif
+
 void
 test01()
 {
@@ -29,7 +35,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   std::wstring wplanet = L"Venus"s;
 #endif
-  std::string u8planet = u8"Mars"s;
+  u8string u8planet = u8"Mars"s;
   std::u16string u16planet = u"Jupiter"s;
   std::u32string u32planet = U"Saturn"s;
 
@@ -37,7 +43,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   VERIFY( wplanet == std::wstring(L"Venus") );
 #endif
-  VERIFY( u8planet == std::string(u8"Mars") );
+  VERIFY( u8planet == u8string(u8"Mars") );
   VERIFY( u16planet == std::u16string(u"Jupiter") );
   VERIFY( u32planet == std::u32string(U"Saturn") );
 }
index 1fe9c53..342789b 100644 (file)
 #include <string_view>
 #include <type_traits>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::u8string_view;
+#else
+using u8string_view = std::string_view;
+#endif
+
 void
 test01()
 {
@@ -29,7 +35,7 @@ test01()
   static_assert(std::is_same<decltype("Hello"sv), std::string_view>::value,
                "\"Hello\"s is std::string_view");
 
-  static_assert(std::is_same<decltype(u8"Hello"sv), std::string_view>::value,
+  static_assert(std::is_same<decltype(u8"Hello"sv), u8string_view>::value,
                "u8\"Hello\"s is std::string_view");
 
 #ifdef _GLIBCXX_USE_WCHAR_T
index ff78596..8843433 100644 (file)
 #include <string_view>
 #include <testsuite_hooks.h>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::u8string_view;
+#else
+using u8string_view = std::string_view;
+#endif
+
 void
 test01()
 {
@@ -29,7 +35,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   std::wstring_view wplanet = L"Venus"sv;
 #endif
-  std::string_view u8planet = u8"Mars"sv;
+  u8string_view u8planet = u8"Mars"sv;
   std::u16string_view u16planet = u"Jupiter"sv;
   std::u32string_view u32planet = U"Saturn"sv;
 
@@ -37,7 +43,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   VERIFY( wplanet == std::wstring_view(L"Venus") );
 #endif
-  VERIFY( u8planet == std::string_view(u8"Mars") );
+  VERIFY( u8planet == u8string_view(u8"Mars") );
   VERIFY( u16planet == std::u16string_view(u"Jupiter") );
   VERIFY( u32planet == std::u32string_view(U"Saturn") );
 }
@@ -51,7 +57,7 @@ test02()
 #ifdef _GLIBCXX_USE_WCHAR_T
   std::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
 #endif
-  std::string_view u8planet_cratered = u8"Mars\0cratered"sv;
+  u8string_view u8planet_cratered = u8"Mars\0cratered"sv;
   std::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv;
   std::u32string_view u32planet_cratered = U"Saturn\0cratered"sv;
 
@@ -59,7 +65,7 @@ test02()
 #ifdef _GLIBCXX_USE_WCHAR_T
   VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) );
 #endif
-  VERIFY( u8planet_cratered == std::string_view(u8"Mars\0cratered", 13) );
+  VERIFY( u8planet_cratered == u8string_view(u8"Mars\0cratered", 13) );
   VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) );
   VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) );
 }
index 767a9be..d1f0e80 100644 (file)
@@ -36,11 +36,15 @@ test01()
   VERIFY(cvt->max_length() == 4);
   VERIFY(cvt->encoding() == 0);
 
-  const char u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
+#ifndef _GLIBCXX_USE_CHAR8_T
+  using char8_t = char;
+#endif
+  const char8_t u8dat_[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
     u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
     u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
     u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
-  const char* const u8dat_end = std::end(u8dat);
+  const char* const u8dat = (const char*)u8dat_;
+  const char* const u8dat_end = (const char*)std::end(u8dat_);
 
   const char16_t u16dat[] = u"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
     u"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
@@ -83,7 +87,7 @@ test01()
 
     VERIFY(res == codecvt_base::ok);
     VERIFY(from_next == u16dat_end);
-    VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0);
+    VERIFY(std::memcmp((void*)buffer, (void*)u8dat_, sizeof(u8dat_)) == 0);
 
     delete[] buffer;
   }
index fc6c936..8df3b2d 100644 (file)
@@ -38,11 +38,15 @@ test01()
   VERIFY(cvt->max_length() == 4);
   VERIFY(cvt->encoding() == 0);
 
-  const char u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
+#ifndef _GLIBCXX_USE_CHAR8_T
+  using char8_t = char;
+#endif
+  const char8_t u8dat_[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
     u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
     u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
     u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
-  const char* const u8dat_end = std::end(u8dat);
+  const char* const u8dat = (const char*)u8dat_;
+  const char* const u8dat_end = (const char*)std::end(u8dat_);
 
   const char32_t u32dat[] = U"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
     U"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
@@ -85,7 +89,7 @@ test01()
 
     VERIFY(res == codecvt_base::ok);
     VERIFY(from_next == u32dat_end);
-    VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0);
+    VERIFY(std::memcmp((void*)buffer, (void*)u8dat_, sizeof(u8dat_)) == 0);
 
     delete[] buffer;
   }
index 331d57f..6d7eafb 100644 (file)
@@ -28,7 +28,7 @@ using std::codecvt_utf8;
 void
 test01()
 {
-  std::string src = u8"1234\U00001111\U0001ffff";
+  std::string src = (const char*)u8"1234\U00001111\U0001ffff";
   wstring_convert<codecvt_utf8<char16_t>, char16_t> c("bad", u"BAD");
 
   // utf-8 to ucs2 conversion should fail on character outside BMP
@@ -51,7 +51,7 @@ test01()
 void
 test02()
 {
-  std::string src = u8"1234\U00001111\U0001ffff";
+  std::string src = (const char*)u8"1234\U00001111\U0001ffff";
   wstring_convert<codecvt_utf8<char16_t, 0x1000>, char16_t> c("bad", u"BAD");
 
   // utf-8 to ucs2 conversion should fail on character above Maxcode=0x1000
@@ -63,7 +63,7 @@ test02()
 void
 test03()
 {
-  std::string src = u8"1234\U00001111\U0001ffff";
+  std::string src = (const char*)u8"1234\U00001111\U0001ffff";
   wstring_convert<codecvt_utf8<char32_t, 0x10000>, char32_t> c("bad", U"BAD");
 
   // utf-8 to ucs4 conversion should fail on character above Maxcode=0x10000
@@ -75,7 +75,7 @@ test03()
 void
 test04()
 {
-  std::string src = u8"1234\U00001111\U0001ffff";
+  std::string src = (const char*)u8"1234\U00001111\U0001ffff";
   wstring_convert<codecvt_utf8<char32_t, 0x1000>, char32_t> c("bad", U"BAD");
 
   // utf-8 to ucs4 conversion should fail on character above Maxcode=0x1000
index aa27048..694845f 100644 (file)
@@ -24,7 +24,7 @@
 void
 test01()
 {
-  const char out[] = u8"\u00A33.50";
+  const auto out = (const char*)u8"\u00A33.50";
   wchar_t in[8] = {};
   std::codecvt_utf8<wchar_t> cvt;
   std::mbstate_t st;
index 602fe63..82ee8ad 100644 (file)
@@ -22,7 +22,7 @@
 #include <string>
 #include <testsuite_hooks.h>
 
-const char expected[] = u8"£¥€";
+const auto expected = (const char*)u8"£¥€";
 const std::size_t expected_len = std::char_traits<char>::length(expected);
 
 template<typename C>
index e83cf98..2e97b4f 100644 (file)
@@ -40,14 +40,14 @@ void test01()
   typedef str_conv<char> sc;
 
   const sc::byte_string berr = "invalid wide string";
-  const sc::wide_string werr = u8"invalid byte string";
+  const sc::wide_string werr = "invalid byte string";
 
   sc c(berr, werr);
   string input = "Stop";
   input += char(0xFF);
   string woutput = c.from_bytes(input);
   VERIFY( input == woutput ); // noconv case doesn't detect invalid input
-  string winput = u8"Stop";
+  string winput = "Stop";
   winput += char(0xFF);
   string output = c.to_bytes(winput);
   VERIFY( winput == output ); // noconv case doesn't detect invalid input
index 404e869..b66e948 100644 (file)
@@ -40,17 +40,17 @@ void test01()
   typedef str_conv<char> wsc;
 
   wsc c;
-  string input = u8"\u00a3 shillings pence";
+  string input = (const char*)u8"\u00a3 shillings pence";
   string woutput = c.from_bytes(input.substr(0, 1));
   auto partial_state = c.state();
   auto partial_count = c.converted();
 
-  auto woutput2 = c.from_bytes(u8"state reset on next conversion");
-  VERIFY( woutput2 == u8"state reset on next conversion" );
+  auto woutput2 = c.from_bytes("state reset on next conversion");
+  VERIFY( woutput2 == "state reset on next conversion" );
 
   wsc c2(new cvt<char>, partial_state);
   woutput += c2.from_bytes(input.substr(partial_count));
-  VERIFY( u8"\u00a3 shillings pence" == woutput );
+  VERIFY( (const char*)u8"\u00a3 shillings pence" == woutput );
 
   string roundtrip = c2.to_bytes(woutput);
   VERIFY( input == roundtrip );
@@ -61,12 +61,12 @@ void test02()
   typedef str_conv<char16_t> wsc;
 
   wsc c;
-  string input = u8"\u00a3 shillings pence";
+  string input = (const char*)u8"\u00a3 shillings pence";
   u16string woutput = c.from_bytes(input.substr(0, 1));
   auto partial_state = c.state();
   auto partial_count = c.converted();
 
-  auto woutput2 = c.from_bytes(u8"state reset on next conversion");
+  auto woutput2 = c.from_bytes("state reset on next conversion");
   VERIFY( woutput2 == u"state reset on next conversion" );
 
   wsc c2(new cvt<char16_t>, partial_state);
@@ -82,12 +82,12 @@ void test03()
   typedef str_conv<char32_t> wsc;
 
   wsc c;
-  string input = u8"\u00a3 shillings pence";
+  string input = (const char*)u8"\u00a3 shillings pence";
   u32string woutput = c.from_bytes(input.substr(0, 1));
   auto partial_state = c.state();
   auto partial_count = c.converted();
 
-  auto woutput2 = c.from_bytes(u8"state reset on next conversion");
+  auto woutput2 = c.from_bytes("state reset on next conversion");
   VERIFY( woutput2 == U"state reset on next conversion" );
 
   wsc c2(new cvt<char32_t>, partial_state);
index 144c858..ac03f36 100644 (file)
 # error "ATOMIC_CHAR_LOCK_FREE must be 1 or 2"
 #endif
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+# ifndef ATOMIC_CHAR8_T_LOCK_FREE
+#  error "ATOMIC_CHAR8_T_LOCK_FREE must be a macro"
+# elif ATOMIC_CHAR8_T_LOCK_FREE != 1 && ATOMIC_CHAR8_T_LOCK_FREE != 2
+#  error "ATOMIC_CHAR8_T_LOCK_FREE must be 1 or 2"
+# endif
+#endif
+
 #ifndef ATOMIC_CHAR16_T_LOCK_FREE 
 # error "ATOMIC_CHAR16_T_LOCK_FREE must be a macro"
 #elif ATOMIC_CHAR16_T_LOCK_FREE != 1 && ATOMIC_CHAR16_T_LOCK_FREE != 2
+# error "ATOMIC_CHAR16_T_LOCK_FREE must be 1 or 2"
 #endif
 
 #ifndef ATOMIC_CHAR32_T_LOCK_FREE 
index c53bb24..47084c4 100644 (file)
@@ -46,6 +46,9 @@ void test01()
   using std::atomic_llong;
   using std::atomic_ullong;
   using std::atomic_wchar_t;
+#ifdef _GLIBCXX_USE_CHAR8_T
+  using std::atomic_char8_t;
+#endif
   using std::atomic_char16_t;
   using std::atomic_char32_t;
 
index 022c3fa..0998a05 100644 (file)
 #include <experimental/string_view>
 #include <type_traits>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::experimental::u8string_view;
+#else
+using u8string_view = std::experimental::string_view;
+#endif
+
 void
 test01()
 {
@@ -28,7 +34,7 @@ test01()
   static_assert(std::is_same<decltype("Hello"sv), std::experimental::string_view>::value,
                "\"Hello\"s is std::string_view");
 
-  static_assert(std::is_same<decltype(u8"Hello"sv), std::experimental::string_view>::value,
+  static_assert(std::is_same<decltype(u8"Hello"sv), u8string_view>::value,
                "u8\"Hello\"s is std::string_view");
 
 #ifdef _GLIBCXX_USE_WCHAR_T
index 3af91c2..e18ee7e 100644 (file)
 #include <experimental/string_view>
 #include <testsuite_hooks.h>
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::experimental::u8string_view;
+#else
+using u8string_view = std::experimental::string_view;
+#endif
+
 void
 test01()
 {
@@ -29,7 +35,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   std::experimental::wstring_view wplanet = L"Venus"sv;
 #endif
-  std::experimental::string_view u8planet = u8"Mars"sv;
+  u8string_view u8planet = u8"Mars"sv;
   std::experimental::u16string_view u16planet = u"Jupiter"sv;
   std::experimental::u32string_view u32planet = U"Saturn"sv;
 
@@ -37,7 +43,7 @@ test01()
 #ifdef _GLIBCXX_USE_WCHAR_T
   VERIFY( wplanet == std::experimental::wstring_view(L"Venus") );
 #endif
-  VERIFY( u8planet == std::experimental::string_view(u8"Mars") );
+  VERIFY( u8planet == u8string_view(u8"Mars") );
   VERIFY( u16planet == std::experimental::u16string_view(u"Jupiter") );
   VERIFY( u32planet == std::experimental::u32string_view(U"Saturn") );
 }
@@ -51,7 +57,7 @@ test02()
 #ifdef _GLIBCXX_USE_WCHAR_T
   std::experimental::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
 #endif
-  std::experimental::string_view u8planet_cratered = u8"Mars\0cratered"sv;
+  u8string_view u8planet_cratered = u8"Mars\0cratered"sv;
   std::experimental::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv;
   std::experimental::u32string_view u32planet_cratered = U"Saturn\0cratered"sv;
 
@@ -61,8 +67,7 @@ test02()
   VERIFY( wplanet_cratered ==
          std::experimental::wstring_view(L"Venus\0cratered", 14) );
 #endif
-  VERIFY( u8planet_cratered ==
-         std::experimental::string_view(u8"Mars\0cratered", 13) );
+  VERIFY( u8planet_cratered == u8string_view(u8"Mars\0cratered", 13) );
   VERIFY( u16planet_cratered ==
          std::experimental::u16string_view(u"Jupiter\0cratered", 16) );
   VERIFY( u32planet_cratered ==