Title
§[format.string.std] char is not formatted as a character when charT is wchar_t
Status
new
Section
[format.string.std]
Submitter
S. B. Tam

Created on 2023-05-26.00:00:00 last changed 17 months ago

Messages

Date: 2023-06-15.00:00:00

[ 2023-06-01; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2023-05-26.00:00:00

(See discussion at microsoft/STL/pull/3723)

[format.string.std] p21 says:

The available integer presentation types for integral types other than bool and charT 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.

This arguably doesn't affect the 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 ([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.

History
Date User Action Args
2023-06-01 14:06:54adminsetmessages: + msg13603
2023-05-26 00:00:00admincreate