]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Rework std::format support for wchar_t
authorJonathan Wakely <jwakely@redhat.com>
Tue, 15 Aug 2023 15:35:22 +0000 (16:35 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 17 Aug 2023 19:24:17 +0000 (20:24 +0100)
commit023a62b77f999b002d4c56a94475684a4d209788
tree02a32da4849f02b3d37d2bc170c882b32fc205a8
parentaeed687f4e08f1364ab60882a012fe740e05a7da
libstdc++: Rework std::format support for wchar_t

This changes how std::format creates wide strings, by replacing uses of
std::ctype<wchar_t>::widen with the recently-added __to_wstring_numeric
helper function. This removes the dependency on the locale, which should
only be used for locale-specific formats such as {:Ld}.

Also disable all the wide string formatting support if the
_GLIBCXX_USE_WCHAR_T macro is not defined. This is consistent with other
wchar_t support being disabled if the library is built without that
macro defined.

libstdc++-v3/ChangeLog:

* include/std/format [_GLIBCXX_USE_WCHAR_T]: Guard all wide
string formatters with this macro.
(__formatter_int::_M_format_int, __formatter_fp::format)
(formatter<const void*, C>::format): Use __to_wstring_numeric
instead of std::ctype::widen.
(__formatter_fp::_M_localize): Use hardcoded wchar_t values
instead of std::ctype::widen.
* testsuite/std/format/functions/format.cc: Add more checks for
wstring formatting of arithmetic types.
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/functions/format.cc