From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DC1F1384DEEF; Fri, 15 Dec 2023 11:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC1F1384DEEF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702640005; bh=GiSdR8642PINWcyDuLSpPoI3k7AowsN4IJt62XuqlQo=; h=From:To:Subject:Date:From; b=L/XPG6n7fJt85GLGrxBdWIJ7hNigt8k/epDU5wl1Did1xUAjDnsFPsxnYSJZ6Yz3s hw3VWDNMxRZFE0E79J+CQFQEt/PQFtb90z3QxVwwtXDW8ORDck+RZAp/v2yG84LPFD msw23wJXWssagYj6OxcHOHZNsQ9AbmgTNPe8jmC4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-8157] libstdc++: Fix %S format of duration with floating-point rep X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 013dd6ab1ca2a04165f3d1f90d498ae66a09058a X-Git-Newrev: 354d684ee933e9638206d62e37204f6e63515125 Message-Id: <20231215113325.DC1F1384DEEF@sourceware.org> Date: Fri, 15 Dec 2023 11:33:25 +0000 (GMT) List-Id: https://gcc.gnu.org/g:354d684ee933e9638206d62e37204f6e63515125 commit r13-8157-g354d684ee933e9638206d62e37204f6e63515125 Author: Jonathan Wakely Date: Thu Dec 14 15:26:42 2023 +0000 libstdc++: Fix %S format of duration with floating-point rep I got the order of arguments to std::format_to wrong. It was in a discarded statement, for a case which wasn't being tested. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_S): Fix order of arguments to std::format_to. * testsuite/20_util/duration/io.cc: Test subsecond duration with floating-point rep. (cherry picked from commit 2ef5200a6fb7311074904a1b4bf7ce750618a068) Diff: --- libstdc++-v3/include/bits/chrono_io.h | 2 +- libstdc++-v3/testsuite/20_util/duration/io.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index c94adff3cec..99cacc97fae 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -1159,7 +1159,7 @@ namespace __format using rep = typename decltype(__ss)::rep; if constexpr (is_floating_point_v) { - __out = std::format_to(__loc, std::move(__out), + __out = std::format_to(std::move(__out), __loc, _GLIBCXX_WIDEN("{:.{}Lg}"), __ss.count(), __hms.fractional_width); diff --git a/libstdc++-v3/testsuite/20_util/duration/io.cc b/libstdc++-v3/testsuite/20_util/duration/io.cc index 034167c6192..5f0f25eac69 100644 --- a/libstdc++-v3/testsuite/20_util/duration/io.cc +++ b/libstdc++-v3/testsuite/20_util/duration/io.cc @@ -96,6 +96,10 @@ test_format() "required by the chrono-specs") != s.npos); } } + + std::chrono::duration d{0.5}; + s = std::format("{}", d); + VERIFY( s == "0.5ms" ); } int main()