https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71107

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-07-18
     Ever confirmed|0                           |1

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes.

Portable testcase:

#include <locale>
#include <codecvt>
#include <cstdio>
#include <string>
#include <assert.h>

int main() {
    wchar_t argv[1][6] = {L"a.out"};
    std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16;

    printf("Input bytes:\n");
    for (size_t i = 0; i < wcslen(argv[0]) * sizeof(wchar_t); i++)
        printf("%x ", (int)((uint8_t *)argv[0])[i]);
    printf("\n");

    std::string bytes = utf16.to_bytes(argv[0]);

    printf("Text after to_bytes: '%s'\n", bytes.c_str());

    printf("Bytes after to_bytes:\n");
    for (size_t i = 0; i < bytes.size(); i++)
        printf("%x ", (int)((const uint8_t *)bytes.c_str())[i]);
    printf("\n");

    std::wstring wide = utf16.from_bytes(bytes);

    printf("Bytes after from_bytes:\n");
    for (size_t i = 0; i < wide.size() * sizeof(wchar_t); i++)
        printf("%x ", (int)((const uint8_t *)wide.c_str())[i]);
    printf("\n");

    std::string bytes2 = utf16.to_bytes(wide);

    printf("Text after to_bytes: '%s'\n", bytes.c_str());

    printf("Bytes after to_bytes:\n");
    for (size_t i = 0; i < bytes.size(); i++)
        printf("%x ", (int)((const uint8_t *)bytes.c_str())[i]);
    printf("\n");

    assert( bytes == bytes2 );;
}

Reply via email to