char
is not formatted as a character when charT
is wchar_t
Section: 28.5.2.2 [format.string.std] Status: New Submitter: S. B. Tam Opened: 2023-05-26 Last modified: 2023-06-01
Priority: 3
View other active issues in [format.string.std].
View all other issues in [format.string.std].
View all issues with New status.
Discussion:
(See discussion at microsoft/STL/pull/3723)
28.5.2.2 [format.string.std] p21 says:The available integer presentation types for integral types other than
bool
andcharT
are specified in Table 68.
When charT
is wchar_t
, the ordinary character type char
falls into this category, and thus a
char
gets formatted as an integer by default, not as a character.
std::format
family, because they are specified in terms of make_format_args
,
which calls the basic_format_arg
constructor, which converts char
to wchar_t
(28.5.8.1 [format.arg] (6.2)). But it does affect the std::formatter<char, wchar_t>
specialization,
which isn't specified to use basic_format_arg
.
This is especially problematic after P2286R8, which makes std::formatter<char, wchar_t>
debug-enabled, but there's no debug format for integral types other than charT
.
Perhaps [format.string.std] should say that the formatting arguments are converted as if through the basic_format_arg
constructor.
At the time of writing, on libstdc++ and libc++, std::formatter<char, wchar_t>
formats the argument as
a character when no specifier is given (godbolt.org/z/nnsEcvna3), while
MSVC STL's std::formatter<char, wchar_t>
outputs the integer value. But I'm about to change MSVC STL to
match the other implementations.
[2023-06-01; Reflector poll]
Set priority to 3 after reflector poll.
Proposed resolution: