Comments (9)
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...);
from fmt.
Your repro (https://godbolt.org/z/EeEEKj1fz) shows that fmt::print
is working. If you meant std::print
then you need to report the issue to the Microsoft STL maintainers. Otherwise please provide the correct repro.
from fmt.
It looks like compilation errors in MSVC 19.40 only happen when including "fmt\std.h"
, <iostream>
or <ostream>
and enabling c++20 mode; I am sorry for the confusion.
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 /std:c++20
or /std:c++latest
. Developer command prompt output is below.
C:\tmp\repro>type repro.cpp
#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::println(L"{}", fmt::format(L"{} : {}", L"Error", L"φαρδιές χορδές"));
}
C:\tmp\repro>cl /EHsc /std:c++20 repro.cpp format.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33617.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
C:\tmp\repro\fmt\xchar.h(271): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
C:\tmp\repro\fmt\xchar.h(89): note: could be 'unknown-type fmt::v10::make_wformat_args(T ...)'
C:\tmp\repro\fmt\xchar.h(271): note: Failed to specialize function template 'unknown-type fmt::v10::make_wformat_args(T ...)'
C:\tmp\repro\fmt\xchar.h(271): note: With the following template arguments:
C:\tmp\repro\fmt\xchar.h(271): note: 'T={std::wstring}'
C:\tmp\repro\fmt\xchar.h(90): note: 'std::make_format_args': ambiguous call to overloaded function
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33617\include\format(3732): note: could be 'auto std::make_format_args<fmt::v10::wformat_context,std::wstring>(std::wstring &)' [found using argument-dependent lookup]
C:\tmp\repro\fmt\base.h(2003): note: or 'fmt::v10::detail::format_arg_store<fmt::v10::wformat_context,1,0,13> fmt::v10::make_format_args<fmt::v10::wformat_context,std::wstring,1,0,13,0>(std::wstring &)'
C:\tmp\repro\fmt\xchar.h(90): note: while trying to match the argument list '(std::wstring)'
C:\tmp\repro\fmt\xchar.h(271): note: the template instantiation context (the oldest one first) is
repro.cpp(9): note: see reference to function template instantiation 'void fmt::v10::println<>(fmt::v10::basic_format_string<wchar_t>)' being compiled
C:\tmp\repro\fmt\xchar.h(280): note: see reference to function template instantiation 'void fmt::v10::print<std::wstring>(fmt::v10::basic_format_string<wchar_t,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>>,std::wstring &&)' being compiled
C:\tmp\repro\fmt\xchar.h(271): error C2661: 'fmt::v10::vprint': no overloaded function takes 1 arguments
C:\tmp\repro\fmt\ostream.h(163): note: could be 'void fmt::v10::vprint(std::basic_ostream<_CharT,std::char_traits<_Elem>> &,fmt::v10::basic_string_view<type_identity<T>::type>,detail::vformat_args<Char>::type)'
C:\tmp\repro\fmt\xchar.h(271): note: 'void fmt::v10::vprint(std::basic_ostream<_CharT,std::char_traits<_Elem>> &,fmt::v10::basic_string_view<type_identity<T>::type>,detail::vformat_args<Char>::type)': expects 3 arguments - 1 provided
C:\tmp\repro\fmt\xchar.h(271): note: while trying to match the argument list '(fmt::v10::wstring_view)'
C:\tmp\repro\fmt\xchar.h(139): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
C:\tmp\repro\fmt\xchar.h(89): note: could be 'unknown-type fmt::v10::make_wformat_args(T ...)'
C:\tmp\repro\fmt\xchar.h(139): note: Failed to specialize function template 'unknown-type fmt::v10::make_wformat_args(T ...)'
C:\tmp\repro\fmt\xchar.h(139): note: With the following template arguments:
C:\tmp\repro\fmt\xchar.h(139): note: 'T={_Ty}'
C:\tmp\repro\fmt\xchar.h(90): note: 'std::make_format_args': ambiguous call to overloaded function
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33617\include\format(3732): note: could be 'auto std::make_format_args<fmt::v10::wformat_context,std::wstring>(std::wstring &)' [found using argument-dependent lookup]
C:\tmp\repro\fmt\base.h(2003): note: or 'fmt::v10::detail::format_arg_store<fmt::v10::wformat_context,1,0,13> fmt::v10::make_format_args<fmt::v10::wformat_context,std::wstring,1,0,13,0>(std::wstring &)'
C:\tmp\repro\fmt\xchar.h(90): note: while trying to match the argument list '(_Ty)'
with
[
_Ty=std::wstring
]
C:\tmp\repro\fmt\xchar.h(139): note: the template instantiation context (the oldest one first) is
repro.cpp(11): note: see reference to function template instantiation 'void fmt::v10::println<std::wstring>(fmt::v10::basic_format_string<wchar_t,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>>,std::wstring &&)' being compiled
C:\tmp\repro\fmt\xchar.h(280): note: see reference to function template instantiation 'std::wstring fmt::v10::format<_Ty>(fmt::v10::basic_format_string<wchar_t,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>>,_Ty &&)' being compiled
with
[
_Ty=std::wstring
]
C:\tmp\repro\fmt\xchar.h(139): error C2661: 'fmt::v10::vformat': no overloaded function takes 1 arguments
C:\tmp\repro\fmt\xchar.h(157): note: could be 'std::basic_string<Char,std::char_traits<Char>,std::allocator<Char>> fmt::v10::vformat(const Locale &,const S &,detail::vformat_args<Char>::type)'
C:\tmp\repro\fmt\xchar.h(139): note: 'std::basic_string<Char,std::char_traits<Char>,std::allocator<Char>> fmt::v10::vformat(const Locale &,const S &,detail::vformat_args<Char>::type)': expects 3 arguments - 1 provided
C:\tmp\repro\fmt\xchar.h(129): note: or 'std::basic_string<_Elem,std::char_traits<_Elem>,std::allocator<_Ty>> fmt::v10::vformat(fmt::v10::basic_string_view<Char>,detail::vformat_args<Char>::type)'
C:\tmp\repro\fmt\xchar.h(139): note: 'std::basic_string<_Elem,std::char_traits<_Elem>,std::allocator<_Ty>> fmt::v10::vformat(fmt::v10::basic_string_view<Char>,detail::vformat_args<Char>::type)': expects 2 arguments - 1 provided
C:\tmp\repro\fmt\format.h(4370): note: or 'std::string fmt::v10::vformat(const Locale &,fmt::v10::string_view,fmt::v10::format_args)'
C:\tmp\repro\fmt\xchar.h(139): note: 'std::string fmt::v10::vformat(const Locale &,fmt::v10::string_view,fmt::v10::format_args)': expects 3 arguments - 1 provided
C:\tmp\repro\fmt\xchar.h(139): note: while trying to match the argument list '(fmt::v10::wstring_view)'
format.cc
Generating Code...
Compiler output from the IDE: msvc1940_fmtlib.txt
from fmt.
Yes, specifying the fmt::
namespace did work. Thanks!
from fmt.
While we're at it... by default, wide strings in print(L"")
raise runtime exceptions, unless you excplicitly enable Unicode translation mode in C runtime wih _setmode()
, available since Visual Studio 2005 (MSVC 14.0):
#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)...
from fmt.
The compilation errors should be fixed by #3899 (thanks to @phprus). For Unicode support make sure to compile with /utf-8
.
from fmt.
/utf-8
compiler switch has no effect on multibyte strings, though it does enable UTF-8 encoded strings to display correctly.
Unless you enable UTF-16 text translation mode with _setmode(_O_WTEXT)
, the C runtime will trigger an exception when it encounters UTF-16 symbols not representable by the current ANSI code page:
Lines 112 to 116 in 12acd79
Exception thrown at 0x00007FFB555C491C in repro.exe: Microsoft C++ exception: std::system_error at memory location 0x00000058402FE578.
KernelBase.dll!RaiseException()
vcruntime140d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 82
repro.exe!fmt::v10::detail::do_throw<std::system_error>(const std::system_error & x) Line 116
> repro.exe!fmt::v10::vprint(_iobuf * f, fmt::v10::basic_string_view<wchar_t> fmt, fmt::v10::basic_format_args<fmt::v10::generic_context<fmt::v10::basic_appender<wchar_t>,wchar_t>> args) Line 258
repro.exe!fmt::v10::vprint(fmt::v10::basic_string_view<wchar_t> fmt, fmt::v10::basic_format_args<fmt::v10::generic_context<fmt::v10::basic_appender<wchar_t>,wchar_t>> args) Line 262
repro.exe!fmt::v10::print<std::wstring>(fmt::v10::basic_format_string<wchar_t,std::wstring> fmt, std::wstring && <args_0>) Line 271
repro.exe!fmt::v10::println<wchar_t const (&)[23]>(fmt::v10::basic_format_string<wchar_t,wchar_t const (&)[23]> fmt, const wchar_t[23] & <args_0>) Line 280
repro.exe!main() Line 19
repro.exe!invoke_main() Line 79
repro.exe!__scrt_common_main_seh() Line 288
repro.exe!__scrt_common_main() Line 331
repro.exe!mainCRTStartup(void * __formal) Line 17
kernel32.dll!00007ffb563654e0()
ntdll.dll!00007ffb57ac485b()
from fmt.
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 /utf-8
and /D
switches.
Note that /D SetMode
enables a conditional compile block that calls _setmode(_O_WTEXT)
) - without this call, the output stops at the first non-English character in string 'Text4`, throwing a runtime exception described above.
C:\tmp\repro>cl /EHsc repro.cpp format.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33617.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BA' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B1' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BD' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BF' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B9' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03AD' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C2' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C3' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C5' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BC' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B2' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BB' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B5' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C1' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03AC' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u901A' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5E38' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u306E' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u6587' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5B57' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5217' cannot be represented in the current code page (1251)
format.cc
Generating Code...
Microsoft (R) Incremental Linker Version 14.40.33617.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
format.obj
C:\tmp\repro>repro
Text0: 'regular strings'
Text1: '????????? ????????????'
Text2: '??????'
Text3: 'wide strings'
Text4: '
C:\tmp\repro>cl /EHsc /utf-8 repro.cpp format.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33617.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
format.cc
Generating Code...
Microsoft (R) Incremental Linker Version 14.40.33617.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
format.obj
C:\tmp\repro>repro
Text0: 'regular strings'
Text1: 'κανονικές συμβολοσειρά'
Text2: '通常の文字列'
Text3: 'wide strings'
Text4: '
C:\tmp\repro>cl /EHsc /D SetMode repro.cpp format.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33617.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BA' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B1' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BD' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BF' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B9' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03AD' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C2' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C3' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C5' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BC' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B2' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03BB' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03B5' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03C1' cannot be represented in the current code page (1251)
repro.cpp(10): warning C4566: character represented by universal-character-name '\u03AC' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u901A' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5E38' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u306E' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u6587' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5B57' cannot be represented in the current code page (1251)
repro.cpp(11): warning C4566: character represented by universal-character-name '\u5217' cannot be represented in the current code page (1251)
format.cc
Generating Code...
Microsoft (R) Incremental Linker Version 14.40.33617.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
format.obj
C:\tmp\repro>repro
Text0: 'regular strings'
Text1: '????????? ????????????'
Text2: '??????'
Text3: 'wide strings'
Text4: 'φαρδιές συμβολοσειρά'
Text5: 'ワイド文字列'
C:\tmp\repro>cl /EHsc /utf-8 /D SetMode repro.cpp format.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33617.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
format.cc
Generating Code...
Microsoft (R) Incremental Linker Version 14.40.33617.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
format.obj
C:\tmp\repro>repro
Text0: 'regular strings'
Text1: 'κανονικές συμβολοσειρά'
Text2: '通常の文字列'
Text3: 'wide strings'
Text4: 'φαρδιές συμβολοσειρά'
Text5: 'ワイド文字列'
from fmt.
Wide streams are not recommended but if you use them you'll have to call _setmode
from the program yourself. The library shouldn't modify global state.
from fmt.
Related Issues (20)
- It would be good to have a customizable separator in fmt::group_digits(...) HOT 1
- fmt::styled and fmt::formatter<std::string> parse deactivate colors/termaps HOT 1
- formatting of variant types HOT 3
- FMT_USE_NONTYPE_TEMPLATE_ARGS detection is wrong on trunk HOT 2
- Support for a single `char` separator in `fmt::join()` HOT 1
- Formatting for strings with custom allocators fails to compile HOT 2
- Advice for extending libfmt for GPU support? HOT 2
- xchar.h extra dependencies HOT 1
- cannot use in CUDA (+MSVC) for newest branch master HOT 1
- Question: what's the difference between string-like formatters and where are they defined? HOT 2
- fmt won't let me specialize a formatter to format mixed character types. HOT 2
- `fmt::isnan` triggers floating-point exception for NaN values HOT 4
- Header-only mode not linking with fmt::ostream HOT 1
- g++-14 compilation error using named arguments inside a generic lambda HOT 2
- Add support for grouping numbers and '_', ',' separators HOT 1
- How do you forward fmt::format_string without explicitly indicating it in the interface? HOT 1
- Fail to build on Ubuntu-18.04 with g++-13.2 HOT 8
- format_as support in fmt/core.h HOT 1
- format_as but with iterator HOT 1
- inclusion of fmt/format-inl.h header causes compile fault (regression after 10.2.1) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fmt.