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

            Bug ID: 80041
           Summary: std::codecvt_utf16<wchar_t> converts to UTF-8 not
                    UTF-16
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <codecvt>
#include <iostream>
#include <iomanip>

int main()
{
  std::codecvt_utf16<wchar_t> conv;
  wchar_t wc = 0x6557;
  char bytes[4] = {0};
  const wchar_t* wnext = nullptr;
  std::mbstate_t st{};
  char* next = nullptr;
  auto r = conv.out(st, &wc, &wc+ 1, wnext, bytes, std::end(bytes), next);
  if (r == std::codecvt_base::ok)
    for (int i = 0; bytes[i]; ++i)
      std::cout << std::hex << (int)(unsigned char)(bytes[i]) << ' ';
  std::cout << '\n';
}

This prints:

e6 95 97 

Which is the UTF-8 encoding for U+6557.

It should print:

65 57

Reply via email to