From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 292933858023; Mon, 17 Jan 2022 19:33:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 292933858023 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-6648] libstdc++: Adjust fast_float's over/underflow behavior for conformance X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: f5c8b82512f9d3eda7e4c71853409d3ac6224777 X-Git-Newrev: 40b0d4472a2591cf27f3a81aa3fba57dc4532648 Message-Id: <20220117193345.292933858023@sourceware.org> Date: Mon, 17 Jan 2022 19:33:45 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 19:33:45 -0000 https://gcc.gnu.org/g:40b0d4472a2591cf27f3a81aa3fba57dc4532648 commit r12-6648-g40b0d4472a2591cf27f3a81aa3fba57dc4532648 Author: Patrick Palka Date: Mon Jan 17 14:32:30 2022 -0500 libstdc++: Adjust fast_float's over/underflow behavior for conformance This changes fast_float's handling of overflow/underflow to be consistent with the standard: instead of returning errc{} and setting value to +-0 or +-infinity, just return errc::result_out_of_range and don't modify value, as per [charconv.from.chars]/1. libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.h (from_chars_advanced): In case of over/underflow, return errc::result_out_of_range and don't modify 'value'. Diff: --- libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 + libstdc++-v3/src/c++17/fast_float/fast_float.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES index ad5a60f9a01..71495d6728b 100644 --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES @@ -1 +1,2 @@ r12-6647 +r12-6648 diff --git a/libstdc++-v3/src/c++17/fast_float/fast_float.h b/libstdc++-v3/src/c++17/fast_float/fast_float.h index c908719ec3a..97d28940944 100644 --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h @@ -2884,6 +2884,15 @@ from_chars_result from_chars_advanced(const char *first, const char *last, // If we called compute_float>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0), // then we need to go the long way around again. This is very uncommon. if(am.power2 < 0) { am = digit_comp(pns, am); } + + if((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) || am.power2 == binary_format::infinite_power()) { + // In case of over/underflow, return result_out_of_range and don't modify value, + // as per [charconv.from.chars]/1. Note that LWG 3081 wants to modify value in + // this case too. + answer.ec = std::errc::result_out_of_range; + return answer; + } + to_float(pns.negative, am, value); return answer; }