From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6DF943858C5F; Thu, 7 Mar 2024 00:30:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DF943858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709771453; bh=fo7AfZRVvv8Sl0PtWa5HxtIi70XWmvYpNdra97lnr6g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YTlz79Ed/OBUYTsB2JwDNOYtm1D8psd0v59s0TMoIF6JvtoW3bompcXMcjis8o7Kw GnDX+2xP72hCTBwZBpXq/p0PoQ8Hskt1xG5ISy3zGIwFS8l5WElgQiKtJf9zqMkv9F v9NJq6UsAO8NdHTCyIunaBq56/ONBbEk9SV1dTaA= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114244] Need to use round when parsing fractional seconds Date: Thu, 07 Mar 2024 00:30:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114244 --- Comment #1 from Jonathan Wakely --- Yup, the seconds part "00.002" is parsed using std::numpunct (in order to handle the locale's decimal point) and then converted to milliseconds using duration_cast: auto& __ng =3D use_facet>(__loc); long double __val; ios_base::iostate __err2{}; __ng.get(__buf, {}, __buf, __err2, __val); if (__is_failed(__err2)) [[unlikely]] __err |=3D __err2; else { duration __fs(__val); __s =3D duration_cast<_Duration>(__fs); } We also use duration_cast when parsing %c and %X using std::time_get, but that's an integer conversion there (but the duration_cast should have been qualified to prevent ADL): __h =3D hours(__tm.tm_hour); __min =3D minutes(__tm.tm_min); __s =3D duration_cast<_Duration>(seconds(__tm.tm_= sec)); and another duration_cast in chrono::from_stream for durations. That one co= uld be used with either integral or floating-point reps. Do we want to parse "00:00:31" as minutes(1)? I don't think we do, so only = the first case where converting long double to milliseconds should be rounded?=