]> git.ipfire.org Git - thirdparty/gcc.git/commit - libstdc++-v3/testsuite/std/format/functions/format.cc
libstdc++: Implement P2909R4 ("Dude, where's my char?") for C++20
authorJonathan Wakely <jwakely@redhat.com>
Wed, 3 Jan 2024 15:35:50 +0000 (15:35 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 8 Jan 2024 01:14:50 +0000 (01:14 +0000)
commit74a0dab18292bef54f316eb086112332befbc6a7
tree71b10673a04967ef74bf90e9e711caf8815d50d3
parentc97436f84cef191618f61912520bc0f0d62d8146
libstdc++: Implement P2909R4 ("Dude, where's my char?") for C++20

This change ensures that char and wchar_t arguments are formatted
consistently when using integer presentation types. This avoids
non-portable std::format output that depends on whether char and wchar_t
happen to be signed or unsigned on the target. Formatting '\xff' as an
integer will now always format 255 and not sometimes -1. This was
approved in Kona 2023 as a DR for C++20 so the change is implemented
unconditionally.

Also make character formatters check for _Pres_c explicitly and call
_M_format_character directly. This avoid the overhead of calling format
and _S_to_character and then calling _M_format_character anyway.

libstdc++-v3/ChangeLog:

* include/bits/version.def (format_uchar): Define.
* include/bits/version.h: Regenerate.
* include/std/format (formatter<C, C>::format): Check for
_Pres_c and call _M_format_character directly. Cast C to its
unsigned equivalent for formatting as an integer.
(formatter<char, wchar_t>::format): Likewise.
(basic_format_arg(T&)): Store char arguments as unsigned char
for formatting to a wide string.
* testsuite/std/format/functions/format.cc: Adjust test. Check
formatting of
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/functions/format.cc