[libcxx-commits] [libcxx] r358908 - [libc++][test] Update some wstring_convert tests for MSVC quirks

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 22 12:08:13 PDT 2019


Author: caseycarter
Date: Mon Apr 22 12:08:13 2019
New Revision: 358908

URL: http://llvm.org/viewvc/llvm-project?rev=358908&view=rev
Log:
[libc++][test] Update some wstring_convert tests for MSVC quirks

Due to MSVC's decision to encode `wchar_t` as UTF-16, it rejects wide
character/string literals that expect a character value greater than
`\xffff`. UTF-16 `wchar_t` is clearly non-conforming, given that the
standard requires wchar_t to be capable of representing all characters
in the supported wide character execution sets, but rejecting e.g.
`\x40003` is a reasonably sane compromise given that encoding choice:
there's an expectation that `\xFOO` produces a single character in the
resulting literal. Consequently `L'\x40003'`/`L"\x40003"` are ill-formed
literals on MSVC. `L'\U00040003'` is a high surrogate (and produces a
warning about ignoring the "second character" in a multi-character
literal), and `L"\U00040003"` is a perfectly-valid `const wchar_t[3]`.

This change updates these tests to use universal-character-names instead
of raw values for the intended character values, which technically makes
them portable even to implementations that don't use a unicode
transformation format encoding for their wide character execution
character set. The two-character literal `L"\u1005e"` is awkward - the
`e` looks like part of the UCN's hex encoding - but necessary to compile
in '03 mode since '03 didn't allow UCNs to be used for members of the
basic execution character set even in character/string literals.

I've also eliminated the extraneous `\x00` "bonus null-terminator" in
some of the string literals which doesn't affect the tested behavior.

I'm sorry about using `*L"\U00040003"` in `conversions.string/to_bytes.pass.cpp`,
but it's correct for platforms with 32-bit wchar_t, *and* doesn't
trigger narrowing warnings as did the prior `CharT(0x40003)`.

Differential Revision: https://reviews.llvm.org/D60950

Modified:
    libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp
    libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp
    libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp

Modified: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp?rev=358908&r1=358907&r2=358908&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp Mon Apr 22 12:08:13 2019
@@ -35,9 +35,9 @@ void TestHelper<CharT, 2>::test() {
     typedef std::wstring_convert<Codecvt> Myconv;
     Myconv myconv;
     assert(myconv.converted() == 0);
-    std::string bs = myconv.to_bytes(L"\x1005");
+    std::string bs = myconv.to_bytes(L"\u1005");
     assert(myconv.converted() == 1);
-    bs = myconv.to_bytes(L"\x1005\x65");
+    bs = myconv.to_bytes(L"\u1005e");
     assert(myconv.converted() == 2);
     std::wstring ws = myconv.from_bytes("\xE1\x80\x85");
     assert(myconv.converted() == 3);
@@ -52,15 +52,16 @@ void TestHelper<CharT, 4>::test() {
     typedef std::wstring_convert<Codecvt> Myconv;
     Myconv myconv;
     assert(myconv.converted() == 0);
-    std::string bs = myconv.to_bytes(L"\x40003");
+    std::string bs = myconv.to_bytes(L"\U00040003");
     assert(myconv.converted() == 1);
-    bs = myconv.to_bytes(L"\x40003\x65");
+    bs = myconv.to_bytes(L"\U00040003e");
     assert(myconv.converted() == 2);
     std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
     assert(myconv.converted() == 4);
   }
 }
 
-int main(int, char**) { TestHelper<wchar_t>::test(); 
+int main(int, char**) {
+  TestHelper<wchar_t>::test();
   return 0;
 }

Modified: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp?rev=358908&r1=358907&r2=358908&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp Mon Apr 22 12:08:13 2019
@@ -35,15 +35,15 @@ void TestHelper<CharT, 2>::test() {
   static_assert((std::is_same<CharT, wchar_t>::value), "");
   {
     std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
-    std::string bs("\xE1\x80\x85\x00");
+    std::string bs("\xE1\x80\x85");
     std::wstring ws = myconv.from_bytes('a');
     assert(ws == L"a");
     ws = myconv.from_bytes(bs.c_str());
-    assert(ws == L"\x1005");
+    assert(ws == L"\u1005");
     ws = myconv.from_bytes(bs);
-    assert(ws == L"\x1005");
+    assert(ws == L"\u1005");
     ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
-    assert(ws == L"\x1005");
+    assert(ws == L"\u1005");
     ws = myconv.from_bytes("");
     assert(ws.size() == 0);
   }
@@ -58,16 +58,17 @@ void TestHelper<CharT, 4>::test() {
     std::wstring ws = myconv.from_bytes('a');
     assert(ws == L"a");
     ws = myconv.from_bytes(bs.c_str());
-    assert(ws == L"\x40003");
+    assert(ws == L"\U00040003");
     ws = myconv.from_bytes(bs);
-    assert(ws == L"\x40003");
+    assert(ws == L"\U00040003");
     ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
-    assert(ws == L"\x40003");
+    assert(ws == L"\U00040003");
     ws = myconv.from_bytes("");
     assert(ws.size() == 0);
   }
 }
 
-int main(int, char**) { TestHelper<wchar_t>::test(); 
+int main(int, char**) {
+  TestHelper<wchar_t>::test();
   return 0;
 }

Modified: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp?rev=358908&r1=358907&r2=358908&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp Mon Apr 22 12:08:13 2019
@@ -35,15 +35,15 @@ void TestHelper<CharT, 2>::test() {
   static_assert((std::is_same<CharT, wchar_t>::value), "");
   {
     std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
-    std::wstring ws(1, CharT(0x1005));
+    std::wstring ws(1, L'\u1005');
     std::string bs = myconv.to_bytes(ws[0]);
-    assert(bs == "\xE1\x80\x85\x00");
+    assert(bs == "\xE1\x80\x85");
     bs = myconv.to_bytes(ws.c_str());
-    assert(bs == "\xE1\x80\x85\x00");
+    assert(bs == "\xE1\x80\x85");
     bs = myconv.to_bytes(ws);
-    assert(bs == "\xE1\x80\x85\x00");
+    assert(bs == "\xE1\x80\x85");
     bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
-    assert(bs == "\xE1\x80\x85\x00");
+    assert(bs == "\xE1\x80\x85");
     bs = myconv.to_bytes(L"");
     assert(bs.size() == 0);
   }
@@ -54,7 +54,7 @@ void TestHelper<CharT, 4>::test() {
   static_assert((std::is_same<CharT, wchar_t>::value), "");
   {
     std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
-    std::wstring ws(1, CharT(0x40003));
+    std::wstring ws(1, *L"\U00040003");
     std::string bs = myconv.to_bytes(ws[0]);
     assert(bs == "\xF1\x80\x80\x83");
     bs = myconv.to_bytes(ws.c_str());
@@ -68,6 +68,7 @@ void TestHelper<CharT, 4>::test() {
   }
 }
 
-int main(int, char**) { TestHelper<wchar_t>::test(); 
+int main(int, char**) {
+  TestHelper<wchar_t>::test();
   return 0;
 }




More information about the libcxx-commits mailing list