libstdc++: Fix formatting of chrono::duration with character rep [PR116755]
commitb349c651ff16240b8cc4225db76479154c941c28
authorJonathan Wakely <jwakely@redhat.com>
Wed, 18 Sep 2024 16:20:29 +0000 (18 17:20 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 9 Oct 2024 12:39:15 +0000 (9 13:39 +0100)
treee14c68336a7672fac624ee4c53d3b551375b4cc6
parent55dbb4b5261d3b0d9fb970ffd3c371bd691badea
libstdc++: Fix formatting of chrono::duration with character rep [PR116755]

Implement Peter Dimov's suggestion for resolving LWG 4118, which is to
use +d.count() so that character types are promoted to an integer type
before formatting them. This didn't have unanimous consensus in the
committee as Howard Hinnant proposed that we should format the rep
consistently with std::format("{}", d.count()) instead. That ends up
being more complicated, because it makes std::formattable a precondition
of operator<< which was not previously the case, and it means that
ios_base::fmtflags from the stream would be ignored because std::format
doesn't use them.

libstdc++-v3/ChangeLog:

PR libstdc++/116755
* include/bits/chrono_io.h (operator<<): Use +d.count() for
duration inserter.
(__formatter_chrono::_M_format): Likewise for %Q format.
* testsuite/20_util/duration/io.cc: Test durations with
character types as reps.
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/20_util/duration/io.cc