[libcxx] r302870 - Cleanup test issues reported by STL @ Microsoft.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Thu May 11 20:38:29 PDT 2017


Author: ericwf
Date: Thu May 11 22:38:28 2017
New Revision: 302870

URL: http://llvm.org/viewvc/llvm-project?rev=302870&view=rev
Log:
Cleanup test issues reported by STL @ Microsoft.

This patch cleans up a number of issues reported by STL, including:

1) Fix duplicate is_convertible test.
2) Move non-standard reference_wrapper tests under test/libcxx
3) Fix assumption that sizeof(wchar_t) == 32 in the codecvt and
   wstring_convert tests.

Added:
    libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/
    libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp
      - copied, changed from r302869, libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp
    libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp
      - copied, changed from r302869, libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp
Removed:
    libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp
    libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp
Modified:
    libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp
    libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp
    libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp
    libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp
    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
    libcxx/trunk/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp

Copied: libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp (from r302869, libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp?p2=libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp&p1=libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp&r1=302869&r2=302870&rev=302870&view=diff
==============================================================================
    (empty)

Copied: libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp (from r302869, libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp?p2=libcxx/trunk/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp&p1=libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp&r1=302869&r2=302870&rev=302870&view=diff
==============================================================================
    (empty)

Modified: libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp?rev=302870&r1=302869&r2=302870&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_out.pass.cpp Thu May 11 22:38:28 2017
@@ -25,307 +25,329 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        typedef std::codecvt_utf16<wchar_t> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xD8));
-        assert(n[1] == char(0xC0));
-        assert(n[2] == char(0xDC));
-        assert(n[3] == char(0x03));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0x10));
-        assert(n[1] == char(0x05));
-        assert(n[2] == char(0xDC));
-        assert(n[3] == char(0x03));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0x04));
-        assert(n[1] == char(0x53));
-        assert(n[2] == char(0xDC));
-        assert(n[3] == char(0x03));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0x00));
-        assert(n[1] == char(0x56));
-        assert(n[2] == char(0xDC));
-        assert(n[3] == char(0x03));
-    }
-    {
-        typedef std::codecvt_utf16<wchar_t, 0x1000> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0x04));
-        assert(n[1] == char(0x53));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0x00));
-        assert(n[1] == char(0x56));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-    }
-    {
-        typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::generate_header> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[6] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xFE));
-        assert(n[1] == char(0xFF));
-        assert(n[2] == char(0xD8));
-        assert(n[3] == char(0xC0));
-        assert(n[4] == char(0xDC));
-        assert(n[5] == char(0x03));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xFE));
-        assert(n[1] == char(0xFF));
-        assert(n[2] == char(0x10));
-        assert(n[3] == char(0x05));
-        assert(n[4] == char(0xDC));
-        assert(n[5] == char(0x03));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xFE));
-        assert(n[1] == char(0xFF));
-        assert(n[2] == char(0x04));
-        assert(n[3] == char(0x53));
-        assert(n[4] == char(0xDC));
-        assert(n[5] == char(0x03));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xFE));
-        assert(n[1] == char(0xFF));
-        assert(n[2] == char(0x00));
-        assert(n[3] == char(0x56));
-        assert(n[4] == char(0xDC));
-        assert(n[5] == char(0x03));
-    }
-
-    {
-        typedef std::codecvt_utf16<wchar_t, 0x10FFFF, std::little_endian> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[1] == char(0xD8));
-        assert(n[0] == char(0xC0));
-        assert(n[3] == char(0xDC));
-        assert(n[2] == char(0x03));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[1] == char(0x10));
-        assert(n[0] == char(0x05));
-        assert(n[3] == char(0xDC));
-        assert(n[2] == char(0x03));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[1] == char(0x04));
-        assert(n[0] == char(0x53));
-        assert(n[3] == char(0xDC));
-        assert(n[2] == char(0x03));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[1] == char(0x00));
-        assert(n[0] == char(0x56));
-        assert(n[3] == char(0xDC));
-        assert(n[2] == char(0x03));
-    }
-    {
-        typedef std::codecvt_utf16<wchar_t, 0x1000, std::little_endian> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[1] == char(0));
-        assert(n[0] == char(0));
-        assert(n[3] == char(0));
-        assert(n[2] == char(0));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[1] == char(0));
-        assert(n[0] == char(0));
-        assert(n[3] == char(0));
-        assert(n[2] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[1] == char(0x04));
-        assert(n[0] == char(0x53));
-        assert(n[3] == char(0));
-        assert(n[2] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[1] == char(0x00));
-        assert(n[0] == char(0x56));
-        assert(n[3] == char(0));
-        assert(n[2] == char(0));
-    }
-    {
-        typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::codecvt_mode(
-                                                         std::generate_header |
-                                                         std::little_endian)> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[6] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+6);
-        assert(n[1] == char(0xFE));
-        assert(n[0] == char(0xFF));
-        assert(n[3] == char(0xD8));
-        assert(n[2] == char(0xC0));
-        assert(n[5] == char(0xDC));
-        assert(n[4] == char(0x03));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[1] == char(0xFE));
-        assert(n[0] == char(0xFF));
-        assert(n[3] == char(0x10));
-        assert(n[2] == char(0x05));
-        assert(n[5] == char(0xDC));
-        assert(n[4] == char(0x03));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[1] == char(0xFE));
-        assert(n[0] == char(0xFF));
-        assert(n[3] == char(0x04));
-        assert(n[2] == char(0x53));
-        assert(n[5] == char(0xDC));
-        assert(n[4] == char(0x03));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+6, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[1] == char(0xFE));
-        assert(n[0] == char(0xFF));
-        assert(n[3] == char(0x00));
-        assert(n[2] == char(0x56));
-        assert(n[5] == char(0xDC));
-        assert(n[4] == char(0x03));
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+void TestHelper<CharT, 2>::test() {
+  // Nothing to do, the conversion in unsupported
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  {
+    typedef std::codecvt_utf16<CharT> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xD8));
+    assert(n[1] == char(0xC0));
+    assert(n[2] == char(0xDC));
+    assert(n[3] == char(0x03));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0x10));
+    assert(n[1] == char(0x05));
+    assert(n[2] == char(0xDC));
+    assert(n[3] == char(0x03));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0x04));
+    assert(n[1] == char(0x53));
+    assert(n[2] == char(0xDC));
+    assert(n[3] == char(0x03));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0x00));
+    assert(n[1] == char(0x56));
+    assert(n[2] == char(0xDC));
+    assert(n[3] == char(0x03));
+  }
+  {
+    typedef std::codecvt_utf16<CharT, 0x1000> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[0] == char(0));
+    assert(n[1] == char(0));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[0] == char(0));
+    assert(n[1] == char(0));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0x04));
+    assert(n[1] == char(0x53));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0x00));
+    assert(n[1] == char(0x56));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+  }
+  {
+    typedef std::codecvt_utf16<CharT, 0x10ffff, std::generate_header> C;
+    C c;
+    CharT w = 0x40003;
+    char n[6] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 6);
+    assert(n[0] == char(0xFE));
+    assert(n[1] == char(0xFF));
+    assert(n[2] == char(0xD8));
+    assert(n[3] == char(0xC0));
+    assert(n[4] == char(0xDC));
+    assert(n[5] == char(0x03));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xFE));
+    assert(n[1] == char(0xFF));
+    assert(n[2] == char(0x10));
+    assert(n[3] == char(0x05));
+    assert(n[4] == char(0xDC));
+    assert(n[5] == char(0x03));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xFE));
+    assert(n[1] == char(0xFF));
+    assert(n[2] == char(0x04));
+    assert(n[3] == char(0x53));
+    assert(n[4] == char(0xDC));
+    assert(n[5] == char(0x03));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xFE));
+    assert(n[1] == char(0xFF));
+    assert(n[2] == char(0x00));
+    assert(n[3] == char(0x56));
+    assert(n[4] == char(0xDC));
+    assert(n[5] == char(0x03));
+  }
+
+  {
+    typedef std::codecvt_utf16<CharT, 0x10FFFF, std::little_endian> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[1] == char(0xD8));
+    assert(n[0] == char(0xC0));
+    assert(n[3] == char(0xDC));
+    assert(n[2] == char(0x03));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[1] == char(0x10));
+    assert(n[0] == char(0x05));
+    assert(n[3] == char(0xDC));
+    assert(n[2] == char(0x03));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[1] == char(0x04));
+    assert(n[0] == char(0x53));
+    assert(n[3] == char(0xDC));
+    assert(n[2] == char(0x03));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[1] == char(0x00));
+    assert(n[0] == char(0x56));
+    assert(n[3] == char(0xDC));
+    assert(n[2] == char(0x03));
+  }
+  {
+    typedef std::codecvt_utf16<CharT, 0x1000, std::little_endian> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[1] == char(0));
+    assert(n[0] == char(0));
+    assert(n[3] == char(0));
+    assert(n[2] == char(0));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[1] == char(0));
+    assert(n[0] == char(0));
+    assert(n[3] == char(0));
+    assert(n[2] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[1] == char(0x04));
+    assert(n[0] == char(0x53));
+    assert(n[3] == char(0));
+    assert(n[2] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[1] == char(0x00));
+    assert(n[0] == char(0x56));
+    assert(n[3] == char(0));
+    assert(n[2] == char(0));
+  }
+  {
+    typedef std::codecvt_utf16<CharT, 0x10ffff,
+                               std::codecvt_mode(std::generate_header |
+                                                 std::little_endian)>
+        C;
+    C c;
+    CharT w = 0x40003;
+    char n[6] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 6);
+    assert(n[1] == char(0xFE));
+    assert(n[0] == char(0xFF));
+    assert(n[3] == char(0xD8));
+    assert(n[2] == char(0xC0));
+    assert(n[5] == char(0xDC));
+    assert(n[4] == char(0x03));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[1] == char(0xFE));
+    assert(n[0] == char(0xFF));
+    assert(n[3] == char(0x10));
+    assert(n[2] == char(0x05));
+    assert(n[5] == char(0xDC));
+    assert(n[4] == char(0x03));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[1] == char(0xFE));
+    assert(n[0] == char(0xFF));
+    assert(n[3] == char(0x04));
+    assert(n[2] == char(0x53));
+    assert(n[5] == char(0xDC));
+    assert(n[4] == char(0x03));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[1] == char(0xFE));
+    assert(n[0] == char(0xFF));
+    assert(n[3] == char(0x00));
+    assert(n[2] == char(0x56));
+    assert(n[5] == char(0xDC));
+    assert(n[4] == char(0x03));
+  }
+}
+
+int main() {
+  TestHelper<char32_t>::test();
+  TestHelper<wchar_t>::test();
 }

Modified: libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp?rev=302870&r1=302869&r2=302870&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_out.pass.cpp Thu May 11 22:38:28 2017
@@ -25,432 +25,302 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        typedef std::codecvt_utf8<wchar_t> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xF1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x80));
-        assert(n[3] == char(0x83));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-    }
-    {
-        typedef std::codecvt_utf8<wchar_t, 0x1000> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-    }
-    {
-        typedef std::codecvt_utf8<wchar_t, 0xFFFFFFFF, std::generate_header> C;
-        C c;
-        wchar_t w = 0x40003;
-        char n[7] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+7);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xF1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x80));
-        assert(n[6] == char(0x83));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-    }
-    {
-        typedef std::codecvt_utf8<char32_t> C;
-        C c;
-        char32_t w = 0x40003;
-        char n[4] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xF1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x80));
-        assert(n[3] == char(0x83));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0x83));
-    }
-    {
-        typedef std::codecvt_utf8<char32_t, 0x1000> C;
-        C c;
-        char32_t w = 0x40003;
-        char n[4] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-    }
-    {
-        typedef std::codecvt_utf8<char32_t, 0xFFFFFFFF, std::generate_header> C;
-        C c;
-        char32_t w = 0x40003;
-        char n[7] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+7);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xF1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x80));
-        assert(n[6] == char(0x83));
-
-        w = 0x1005;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0x83));
-    }
-    {
-        typedef std::codecvt_utf8<char16_t> C;
-        C c;
-        char16_t w = 0x1005;
-        char n[4] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0x85));
-        assert(n[3] == char(0));
-    }
-    {
-        typedef std::codecvt_utf8<char16_t, 0x1000> C;
-        C c;
-        char16_t w = 0x1005;
-        char n[4] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == &w);
-        assert(np == n);
-        assert(n[0] == char(0));
-        assert(n[1] == char(0));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-        assert(n[1] == char(0x93));
-        assert(n[2] == char(0));
-        assert(n[3] == char(0));
-    }
-    {
-        typedef std::codecvt_utf8<char16_t, 0xFFFFFFFF, std::generate_header> C;
-        C c;
-        char16_t w = 0x1005;
-        char n[7] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0));
-
-        w = 0x453;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0));
-
-        w = 0x56;
-        r = c.out(m, &w, &w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == &w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-        assert(n[4] == char(0x93));
-        assert(n[5] == char(0x85));
-        assert(n[6] == char(0));
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+void TestHelper<CharT, 2>::test() {
+  {
+    typedef std::codecvt_utf8<CharT> C;
+    C c;
+    CharT w = 0x1005;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 3);
+    assert(n[0] == char(0xE1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0));
+  }
+  {
+    typedef std::codecvt_utf8<CharT, 0x1000> C;
+    C c;
+    CharT w = 0x1005;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[0] == char(0));
+    assert(n[1] == char(0));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+  }
+  {
+    typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::generate_header> C;
+    C c;
+    CharT w = 0x1005;
+    char n[7] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 6);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xE1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 5);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xD1));
+    assert(n[4] == char(0x93));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0x56));
+    assert(n[4] == char(0x93));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0));
+  }
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  {
+    typedef std::codecvt_utf8<CharT> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xF1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x80));
+    assert(n[3] == char(0x83));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 3);
+    assert(n[0] == char(0xE1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0x83));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0x83));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0x85));
+    assert(n[3] == char(0x83));
+  }
+  {
+    typedef std::codecvt_utf8<CharT, 0x1000> C;
+    C c;
+    CharT w = 0x40003;
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[0] == char(0));
+    assert(n[1] == char(0));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == &w);
+    assert(np == n);
+    assert(n[0] == char(0));
+    assert(n[1] == char(0));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+    assert(n[1] == char(0x93));
+    assert(n[2] == char(0));
+    assert(n[3] == char(0));
+  }
+  {
+    typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::generate_header> C;
+    C c;
+    CharT w = 0x40003;
+    char n[7] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 7);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xF1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x80));
+    assert(n[6] == char(0x83));
+
+    w = 0x1005;
+    r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 6);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xE1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0x83));
+
+    w = 0x453;
+    r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 5);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xD1));
+    assert(n[4] == char(0x93));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0x83));
+
+    w = 0x56;
+    r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == &w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0x56));
+    assert(n[4] == char(0x93));
+    assert(n[5] == char(0x85));
+    assert(n[6] == char(0x83));
+  }
+}
+
+int main() {
+  TestHelper<wchar_t>::test();
+  TestHelper<char32_t>::test();
+  TestHelper<char16_t>::test();
 }

Modified: libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp?rev=302870&r1=302869&r2=302870&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_in.pass.cpp Thu May 11 22:38:28 2017
@@ -25,348 +25,220 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t> C;
-        C c;
-        wchar_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
-        C c;
-        wchar_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::consume_header> C;
-        C c;
-        wchar_t w[2] = {0};
-        char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
-        wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t> C;
-        C c;
-        char32_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char32_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
-        C c;
-        char32_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char32_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::consume_header> C;
-        C c;
-        char32_t w[2] = {0};
-        char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char32_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char16_t> C;
-        C c;
-        char16_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char16_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
-        C c;
-        char16_t w[2] = {0};
-        char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char16_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::consume_header> C;
-        C c;
-        char16_t w[2] = {0};
-        char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
-        char16_t* wp = nullptr;
-        std::mbstate_t m;
-        const char* np = nullptr;
-        std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(w[0] == 0xD8C0);
-        assert(w[1] == 0xDC03);
-
-        n[0] = char(0xE1);
-        n[1] = char(0x80);
-        n[2] = char(0x85);
-        r = c.in(m, n, n+3, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(w[0] == 0x1005);
-
-        n[0] = char(0xD1);
-        n[1] = char(0x93);
-        r = c.in(m, n, n+2, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(w[0] == 0x0453);
-
-        n[0] = char(0x56);
-        r = c.in(m, n, n+1, np, w, w+2, wp);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(w[0] == 0x0056);
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+void TestHelper<CharT, 2>::test() {
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
+    C c;
+    CharT w[2] = {0};
+    char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
+    CharT* wp = nullptr;
+    std::mbstate_t m;
+    const char* np = nullptr;
+    std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    n[0] = char(0xE1);
+    n[1] = char(0x80);
+    n[2] = char(0x85);
+    r = c.in(m, n, n + 3, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    n[0] = char(0xD1);
+    n[1] = char(0x93);
+    r = c.in(m, n, n + 2, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(w[0] == 0x0453);
+
+    n[0] = char(0x56);
+    r = c.in(m, n, n + 1, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(w[0] == 0x0056);
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::consume_header> C;
+    C c;
+    CharT w[2] = {0};
+    char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
+                 char(0x80), char(0x80), char(0x83)};
+    CharT* wp = nullptr;
+    std::mbstate_t m;
+    const char* np = nullptr;
+    std::codecvt_base::result r = c.in(m, n, n + 7, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 7);
+    assert(w[0] == 0xD8C0);
+    assert(w[1] == 0xDC03);
+
+    n[0] = char(0xE1);
+    n[1] = char(0x80);
+    n[2] = char(0x85);
+    r = c.in(m, n, n + 3, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 3);
+    assert(w[0] == 0x1005);
+
+    n[0] = char(0xD1);
+    n[1] = char(0x93);
+    r = c.in(m, n, n + 2, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(w[0] == 0x0453);
+
+    n[0] = char(0x56);
+    r = c.in(m, n, n + 1, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(w[0] == 0x0056);
+  }
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  {
+    typedef std::codecvt_utf8_utf16<CharT> C;
+    C c;
+    CharT w[2] = {0};
+    char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
+    CharT* wp = nullptr;
+    std::mbstate_t m;
+    const char* np = nullptr;
+    std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 4);
+    assert(w[0] == 0xD8C0);
+    assert(w[1] == 0xDC03);
+
+    n[0] = char(0xE1);
+    n[1] = char(0x80);
+    n[2] = char(0x85);
+    r = c.in(m, n, n + 3, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 3);
+    assert(w[0] == 0x1005);
+
+    n[0] = char(0xD1);
+    n[1] = char(0x93);
+    r = c.in(m, n, n + 2, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(w[0] == 0x0453);
+
+    n[0] = char(0x56);
+    r = c.in(m, n, n + 1, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(w[0] == 0x0056);
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
+    C c;
+    CharT w[2] = {0};
+    char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
+    CharT* wp = nullptr;
+    std::mbstate_t m;
+    const char* np = nullptr;
+    std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    n[0] = char(0xE1);
+    n[1] = char(0x80);
+    n[2] = char(0x85);
+    r = c.in(m, n, n + 3, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    n[0] = char(0xD1);
+    n[1] = char(0x93);
+    r = c.in(m, n, n + 2, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(w[0] == 0x0453);
+
+    n[0] = char(0x56);
+    r = c.in(m, n, n + 1, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(w[0] == 0x0056);
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::consume_header> C;
+    C c;
+    CharT w[2] = {0};
+    char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
+                 char(0x80), char(0x80), char(0x83)};
+    CharT* wp = nullptr;
+    std::mbstate_t m;
+    const char* np = nullptr;
+    std::codecvt_base::result r = c.in(m, n, n + 7, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 7);
+    assert(w[0] == 0xD8C0);
+    assert(w[1] == 0xDC03);
+
+    n[0] = char(0xE1);
+    n[1] = char(0x80);
+    n[2] = char(0x85);
+    r = c.in(m, n, n + 3, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 3);
+    assert(w[0] == 0x1005);
+
+    n[0] = char(0xD1);
+    n[1] = char(0x93);
+    r = c.in(m, n, n + 2, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(w[0] == 0x0453);
+
+    n[0] = char(0x56);
+    r = c.in(m, n, n + 1, np, w, w + 2, wp);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(w[0] == 0x0056);
+  }
+}
+
+int main() {
+#ifndef _WIN32
+  TestHelper<wchar_t>::test();
+#endif
+  TestHelper<char32_t>::test();
+  TestHelper<char16_t>::test();
 }

Modified: libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp?rev=302870&r1=302869&r2=302870&view=diff
==============================================================================
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp (original)
+++ libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_utf16_out.pass.cpp Thu May 11 22:38:28 2017
@@ -25,391 +25,285 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t> C;
-        C c;
-        wchar_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(n[0] == char(0xF1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x80));
-        assert(n[3] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
-        C c;
-        wchar_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::generate_header> C;
-        C c;
-        wchar_t w[2] = {0xD8C0, 0xDC03};
-        char n[7] = {0};
-        const wchar_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xF1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x80));
-        assert(n[6] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t> C;
-        C c;
-        char32_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(n[0] == char(0xF1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x80));
-        assert(n[3] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
-        C c;
-        char32_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::generate_header> C;
-        C c;
-        char32_t w[2] = {0xD8C0, 0xDC03};
-        char n[7] = {0};
-        const char32_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xF1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x80));
-        assert(n[6] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-    }
-
-    {
-        typedef std::codecvt_utf8_utf16<char16_t> C;
-        C c;
-        char16_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+4);
-        assert(n[0] == char(0xF1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x80));
-        assert(n[3] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+3);
-        assert(n[0] == char(0xE1));
-        assert(n[1] == char(0x80));
-        assert(n[2] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
-        C c;
-        char16_t w[2] = {0xD8C0, 0xDC03};
-        char n[4] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::error);
-        assert(wp == w);
-        assert(np == n);
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+2);
-        assert(n[0] == char(0xD1));
-        assert(n[1] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+4, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+1);
-        assert(n[0] == char(0x56));
-    }
-    {
-        typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::generate_header> C;
-        C c;
-        char16_t w[2] = {0xD8C0, 0xDC03};
-        char n[7] = {0};
-        const char16_t* wp = nullptr;
-        std::mbstate_t m;
-        char* np = nullptr;
-        std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+2);
-        assert(np == n+7);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xF1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x80));
-        assert(n[6] == char(0x83));
-
-        w[0] = 0x1005;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+6);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xE1));
-        assert(n[4] == char(0x80));
-        assert(n[5] == char(0x85));
-
-        w[0] = 0x453;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+5);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0xD1));
-        assert(n[4] == char(0x93));
-
-        w[0] = 0x56;
-        r = c.out(m, w, w+1, wp, n, n+7, np);
-        assert(r == std::codecvt_base::ok);
-        assert(wp == w+1);
-        assert(np == n+4);
-        assert(n[0] == char(0xEF));
-        assert(n[1] == char(0xBB));
-        assert(n[2] == char(0xBF));
-        assert(n[3] == char(0x56));
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+void TestHelper<CharT, 2>::test() {
+  {
+    typedef std::codecvt_utf8_utf16<CharT> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 4);
+    assert(n[0] == char(0xF1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x80));
+    assert(n[3] == char(0x83));
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 3);
+    assert(n[0] == char(0xE1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x85));
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[7] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 7);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xF1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x80));
+    assert(n[6] == char(0x83));
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 6);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xE1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x85));
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 5);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xD1));
+    assert(n[4] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0x56));
+  }
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  {
+    typedef std::codecvt_utf8_utf16<CharT> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 4);
+    assert(n[0] == char(0xF1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x80));
+    assert(n[3] == char(0x83));
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 3);
+    assert(n[0] == char(0xE1));
+    assert(n[1] == char(0x80));
+    assert(n[2] == char(0x85));
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[4] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::error);
+    assert(wp == w);
+    assert(np == n);
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 2);
+    assert(n[0] == char(0xD1));
+    assert(n[1] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 4, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 1);
+    assert(n[0] == char(0x56));
+  }
+  {
+    typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
+    C c;
+    CharT w[2] = {0xD8C0, 0xDC03};
+    char n[7] = {0};
+    const CharT* wp = nullptr;
+    std::mbstate_t m;
+    char* np = nullptr;
+    std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 2);
+    assert(np == n + 7);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xF1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x80));
+    assert(n[6] == char(0x83));
+
+    w[0] = 0x1005;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 6);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xE1));
+    assert(n[4] == char(0x80));
+    assert(n[5] == char(0x85));
+
+    w[0] = 0x453;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 5);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0xD1));
+    assert(n[4] == char(0x93));
+
+    w[0] = 0x56;
+    r = c.out(m, w, w + 1, wp, n, n + 7, np);
+    assert(r == std::codecvt_base::ok);
+    assert(wp == w + 1);
+    assert(np == n + 4);
+    assert(n[0] == char(0xEF));
+    assert(n[1] == char(0xBB));
+    assert(n[2] == char(0xBF));
+    assert(n[3] == char(0x56));
+  }
+}
+
+int main() {
+#ifndef _WIN32
+  TestHelper<wchar_t>::test();
+#endif
+  TestHelper<char32_t>::test();
+  TestHelper<char16_t>::test();
 }

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=302870&r1=302869&r2=302870&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 Thu May 11 22:38:28 2017
@@ -17,9 +17,39 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    typedef std::codecvt_utf8<wchar_t> Codecvt;
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+void TestHelper<CharT, 2>::test() {
+  static_assert(std::is_same<CharT, wchar_t>::value, "");
+  {
+    typedef std::codecvt_utf8<CharT> Codecvt;
+    typedef std::wstring_convert<Codecvt> Myconv;
+    Myconv myconv;
+    assert(myconv.converted() == 0);
+    std::string bs = myconv.to_bytes(L"\x1005");
+    assert(myconv.converted() == 1);
+    bs = myconv.to_bytes(L"\x1005\x65");
+    assert(myconv.converted() == 2);
+    std::wstring ws = myconv.from_bytes("\xE1\x80\x85");
+    assert(myconv.converted() == 3);
+  }
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  static_assert(std::is_same<CharT, wchar_t>::value, "");
+  {
+    typedef std::codecvt_utf8<CharT> Codecvt;
     typedef std::wstring_convert<Codecvt> Myconv;
     Myconv myconv;
     assert(myconv.converted() == 0);
@@ -29,4 +59,7 @@ int main()
     assert(myconv.converted() == 2);
     std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
     assert(myconv.converted() == 4);
+  }
 }
+
+int main() { TestHelper<wchar_t>::test(); }

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=302870&r1=302869&r2=302870&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 Thu May 11 22:38:28 2017
@@ -20,20 +20,53 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
-        std::string bs("\xF1\x80\x80\x83");
-        std::wstring ws = myconv.from_bytes('a');
-        assert(ws == L"a");
-        ws = myconv.from_bytes(bs.c_str());
-        assert(ws == L"\x40003");
-        ws = myconv.from_bytes(bs);
-        assert(ws == L"\x40003");
-        ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
-        assert(ws == L"\x40003");
-        ws = myconv.from_bytes("");
-        assert(ws.size() == 0);
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+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::wstring ws = myconv.from_bytes('a');
+    assert(ws == L"a");
+    ws = myconv.from_bytes(bs.c_str());
+    assert(ws == L"\x1005");
+    ws = myconv.from_bytes(bs);
+    assert(ws == L"\x1005");
+    ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
+    assert(ws == L"\x1005");
+    ws = myconv.from_bytes("");
+    assert(ws.size() == 0);
+  }
+}
+
+template <class CharT>
+void TestHelper<CharT, 4>::test() {
+  static_assert(std::is_same<CharT, wchar_t>::value, "");
+  {
+    std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
+    std::string bs("\xF1\x80\x80\x83");
+    std::wstring ws = myconv.from_bytes('a');
+    assert(ws == L"a");
+    ws = myconv.from_bytes(bs.c_str());
+    assert(ws == L"\x40003");
+    ws = myconv.from_bytes(bs);
+    assert(ws == L"\x40003");
+    ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
+    assert(ws == L"\x40003");
+    ws = myconv.from_bytes("");
+    assert(ws.size() == 0);
+  }
 }
+
+int main() { TestHelper<wchar_t>::test(); }

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=302870&r1=302869&r2=302870&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 Thu May 11 22:38:28 2017
@@ -20,20 +20,53 @@
 #include <codecvt>
 #include <cassert>
 
-int main()
-{
-    {
-        std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
-        std::wstring ws(1, L'\x40003');
-        std::string bs = myconv.to_bytes(ws[0]);
-        assert(bs == "\xF1\x80\x80\x83");
-        bs = myconv.to_bytes(ws.c_str());
-        assert(bs == "\xF1\x80\x80\x83");
-        bs = myconv.to_bytes(ws);
-        assert(bs == "\xF1\x80\x80\x83");
-        bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
-        assert(bs == "\xF1\x80\x80\x83");
-        bs = myconv.to_bytes(L"");
-        assert(bs.size() == 0);
-    }
+template <class CharT, size_t = sizeof(CharT)>
+struct TestHelper;
+template <class CharT>
+struct TestHelper<CharT, 2> {
+  static void test();
+};
+template <class CharT>
+struct TestHelper<CharT, 4> {
+  static void test();
+};
+
+template <class CharT>
+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::string bs = myconv.to_bytes(ws[0]);
+    assert(bs == "\xE1\x80\x85\x00");
+    bs = myconv.to_bytes(ws.c_str());
+    assert(bs == "\xE1\x80\x85\x00");
+    bs = myconv.to_bytes(ws);
+    assert(bs == "\xE1\x80\x85\x00");
+    bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
+    assert(bs == "\xE1\x80\x85\x00");
+    bs = myconv.to_bytes(L"");
+    assert(bs.size() == 0);
+  }
+}
+
+template <class CharT>
+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::string bs = myconv.to_bytes(ws[0]);
+    assert(bs == "\xF1\x80\x80\x83");
+    bs = myconv.to_bytes(ws.c_str());
+    assert(bs == "\xF1\x80\x80\x83");
+    bs = myconv.to_bytes(ws);
+    assert(bs == "\xF1\x80\x80\x83");
+    bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
+    assert(bs == "\xF1\x80\x80\x83");
+    bs = myconv.to_bytes(L"");
+    assert(bs.size() == 0);
+  }
 }
+
+int main() { TestHelper<wchar_t>::test(); }

Removed: libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp?rev=302869&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/function.objects/refwrap/binary.pass.cpp (removed)
@@ -1,80 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <functional>
-
-// reference_wrapper
-
-// check for deriving from binary_function
-
-#include <functional>
-#include <type_traits>
-
-class functor1
-    : public std::unary_function<int, char>
-{
-};
-
-class functor2
-    : public std::binary_function<char, int, double>
-{
-};
-
-class functor3
-    : public std::unary_function<int, int>,
-      public std::binary_function<char, int, double>
-{
-public:
-    typedef float result_type;
-};
-
-class functor4
-    : public std::unary_function<int, int>,
-      public std::binary_function<char, int, double>
-{
-public:
-};
-
-struct C
-{
-    typedef int argument_type;
-    typedef int result_type;
-};
-
-int main()
-{
-    static_assert((!std::is_base_of<std::binary_function<int, char, int>,
-                                    std::reference_wrapper<functor1> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<char, int, double>,
-                                   std::reference_wrapper<functor2> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<char, int, double>,
-                                   std::reference_wrapper<functor3> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<char, int, double>,
-                                   std::reference_wrapper<functor4> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<int, int, int>,
-                                    std::reference_wrapper<C> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<int, int, float>,
-                                    std::reference_wrapper<float ()> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<int, int, float>,
-                                   std::reference_wrapper<float (int)> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<int, int, float>,
-                                    std::reference_wrapper<float (int, int)> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<int, int, float>,
-                                    std::reference_wrapper<float(*)()> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<int, int, float>,
-                                   std::reference_wrapper<float(*)(int)> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<int, int, float>,
-                                    std::reference_wrapper<float(*)(int, int)> >::value), "");
-    static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
-                                   std::reference_wrapper<float(C::*)()> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<C*, int, float>,
-                                   std::reference_wrapper<float(C::*)(int)> >::value), "");
-    static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
-                                   std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
-}

Removed: libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp?rev=302869&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/function.objects/refwrap/unary.pass.cpp (removed)
@@ -1,78 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <functional>
-
-// reference_wrapper
-
-// check for deriving from unary_function
-
-#include <functional>
-#include <type_traits>
-
-class functor1
-    : public std::unary_function<int, char>
-{
-};
-
-class functor2
-    : public std::binary_function<char, int, double>
-{
-};
-
-class functor3
-    : public std::unary_function<int, int>,
-      public std::binary_function<char, int, double>
-{
-public:
-    typedef float result_type;
-};
-
-class functor4
-    : public std::unary_function<int, int>,
-      public std::binary_function<char, int, double>
-{
-public:
-};
-
-struct C
-{
-    typedef int argument_type;
-    typedef int result_type;
-};
-
-int main()
-{
-    static_assert((std::is_base_of<std::unary_function<int, char>,
-                                   std::reference_wrapper<functor1> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<char, int>,
-                                    std::reference_wrapper<functor2> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<int, int>,
-                                   std::reference_wrapper<functor3> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<int, int>,
-                                   std::reference_wrapper<functor4> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<int, int>,
-                                    std::reference_wrapper<C> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<int, float>,
-                                    std::reference_wrapper<float(*)()> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<int, float>,
-                                   std::reference_wrapper<float (int)> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<int, float>,
-                                    std::reference_wrapper<float (int, int)> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<int, float>,
-                                   std::reference_wrapper<float(*)(int)> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<int, float>,
-                                    std::reference_wrapper<float(*)(int, int)> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<C*, float>,
-                                   std::reference_wrapper<float(C::*)()> >::value), "");
-    static_assert((std::is_base_of<std::unary_function<const volatile C*, float>,
-                                   std::reference_wrapper<float(C::*)() const volatile> >::value), "");
-    static_assert((!std::is_base_of<std::unary_function<C*, float>,
-                                   std::reference_wrapper<float(C::*)(int)> >::value), "");
-}

Modified: libcxx/trunk/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp?rev=302870&r1=302869&r2=302870&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp Thu May 11 22:38:28 2017
@@ -120,7 +120,9 @@ int main()
     static_assert((!std::is_convertible<ConstFunction, Function>::value), "");
     static_assert((!std::is_convertible<ConstFunction, Function*>::value), "");
     static_assert((!std::is_convertible<ConstFunction, Function&>::value), "");
-    static_assert((!std::is_convertible<ConstFunction, Function>::value), "");
+#if TEST_STD_VER >= 11
+    static_assert((!std::is_convertible<ConstFunction, Function&&>::value), "");
+#endif
     static_assert((!std::is_convertible<Function*, ConstFunction>::value), "");
     static_assert((!std::is_convertible<Function&, ConstFunction>::value), "");
     static_assert((!std::is_convertible<ConstFunction, ConstFunction>::value), "");




More information about the cfe-commits mailing list