-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xchar.h
wide strings are broken in VS 2022 preview 17.10
#3898
Comments
Your repro (https://godbolt.org/z/EeEEKj1fz) shows that |
It looks like compilation errors in MSVC 19.40 only happen when including The latest available on godbolt is MSVC 19.38, which works fine. I've updated the code example above, it compiles successfully in c++14 / c++17 modes, and breaks with
Compiler output from the IDE: msvc1940_fmtlib.txt |
Try replacing lines Lines 90 to 91 in c17816c
with -> decltype(fmt::make_format_args<wformat_context>(args...)) {
return fmt::make_format_args<wformat_context>(args...); |
Yes, specifying the |
While we're at it... by default, wide strings in #include <io.h>
#include <fnctrl.h>
_setmode(_fileno(stdout), _O_UWTEXT);
_setmode(_fileno(stderr), _O_UWTEXT); I believe this is safe to enable by default. CRT code page translation bugs were ironed out long time ago, according to posts by the late Michael S. Kaplan, and Windows 10 console implementaion natively supports Unicode UTF-8 in the text buffer since version 1809, replacing UCS-2 encoding used by Windows API (aka Win32)... |
Unless you enable UTF-16 text translation mode with Lines 112 to 116 in 12acd79
|
Here is my test case which prints three text strings, two of which contain symbols outside of my current system locale, first encoded as UTF-8 strings and then as UTF-16 wide strings. C:\tmp\repro>type repro.cpp
#include "fmt\format.h"
#include "fmt\xchar.h"
#include <io.h>
#include <fcntl.h>
int main()
{
fmt::println("Text0: 'regular strings'");
fmt::println("Text1: {}", "'κανονικές συμβολοσειρά'");
fmt::println("{}", fmt::format("{}: {}", "Text2", "'通常の文字列'"));
#ifdef SetMode
//Runtime exception in vcruntime140d.dll if undefined
_setmode(_fileno(stdout), _O_WTEXT);
#endif
fmt::println(L"Text3: 'wide strings'");
fmt::println(L"Text4: {}", L"'φαρδιές συμβολοσειρά'");
fmt::println(L"{}", fmt::format(L"{}: {}", L"Text5", L"'ワイド文字列'"));
} Here is the output from four variants of the executable file, compiled with combinations of
|
Wide streams are not recommended but if you use them you'll have to call |
In most recent MSVC 19.40 (Visual Studio 2022 17.10 preview 2), calling
println()
withwhar_t
andstd:wstring
, orprint
withstd:wstring
, will result in compiler errors[Edit] in c++20 mode when you also include
"fmt\std.h"
,<iostream>
or<ostream>
.It worked fine in previous versions like MSVC 19.38:
https://godbolt.org/z/cqoz8esjn
Now
print()
withwhar_t
kind of works, but it will raise runtime exceptions for any non-ASCII symbols by default, unless I call _setmode to enable one of Unicode text translation modes in the CRT - then it works fine and prints correct non-ASCII symbols; in binary mode, it prints some mojibake.print()
andprintln()
seem to work fine with UTF-8 strings - although displaying correct non-ASCII symbols requires/utf-8
compiler option, otherwise these will show as question marks or a different kind of mojibake.I'm back to using
wprintf_s()
as I need to print localized COM error messages supplied by Windows API, andstd::print
only supports UTF-8 but notwchar_t
.The text was updated successfully, but these errors were encountered: