LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47302 - mingw-w64: std::wcout after _setmode(_fileno(stdout), _O_WTEXT) doesn't work
Summary: mingw-w64: std::wcout after _setmode(_fileno(stdout), _O_WTEXT) doesn't work
Status: NEW
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 10.0
Hardware: PC Windows NT
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-24 22:14 PDT by Long Nguyen
Modified: 2020-08-24 22:24 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Long Nguyen 2020-08-24 22:14:49 PDT
Take this code snippet:
#include <iostream>
#include <io.h>
#include <fcntl.h>

int wmain(int argc, const wchar_t* argv[])
{
    _setmode(_fileno(stdout), _O_WTEXT);
    std::wcout << L"Thử nghiệm\n";
    return 0;
}

On MS STL, this correctly outputs the string, but on libc++ it outputs nothing.

Additional notes:
Add -municode when compiling with clang, and add /utf-8 when compiling with MSVC
Comment 1 Long Nguyen 2020-08-24 22:24:21 PDT
In contrast, the following equivalent C code works on both:
#include <stdio.h>
#include <io.h>
#include <fcntl.h>

int wmain(int argc, const wchar_t* argv[])
{
    _setmode(_fileno(stdout), _O_WTEXT);
    _putws(L"Thử nghiệm\n");
    return 0;
}