Skip to content

xchar.h wide strings are broken in VS 2022 preview 17.10 #3898

Description

@DmitryKo76

In most recent MSVC 19.40 (Visual Studio 2022 17.10 preview 2), calling println() with whar_t and std:wstring, or print with std:wstring, will result in compiler errors
[Edit] in c++20 mode when you also include "fmt\std.h", <iostream> or <ostream>.

#include <fmt/format.h>
#include <fmt/xchar.h>
//Compile error in MSVC 19.40 (VS 2022 17.10 preview) with /std:c++20 and one of the following headers
#include "fmt\std.h"
#include <ostream>
#include <iostream>
int main() {
	fmt::println(L"Error: φαρδιές χορδές");
	fmt::println(L"Error: {}", L"φαρδιές χορδές");
	fmt::print(L"{}", format(L"Errror: {}", L"φαρδιές χορδές") );
}
fmt\xchar.h(271,41): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
fmt\xchar.h(271,10): error C2661: 'fmt::v10::vprint': no overloaded function takes 1 arguments
fmt\xchar.h(139,47): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
fmt\xchar.h(139,10): error C2661: 'fmt::v10::vformat': no overloaded function takes 1 arguments

It worked fine in previous versions like MSVC 19.38:
https://godbolt.org/z/cqoz8esjn


Now print() with whar_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() and println() 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, and std::print only supports UTF-8 but not wchar_t.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions