]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Adjust fast_float's over/underflow behavior for conformance
authorPatrick Palka <ppalka@redhat.com>
Mon, 17 Jan 2022 19:32:30 +0000 (14:32 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 17 Jan 2022 19:32:30 +0000 (14:32 -0500)
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'.

libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
libstdc++-v3/src/c++17/fast_float/fast_float.h

index ad5a60f9a0112f9837b7bcdc95fe3acb10f036b6..71495d6728bf115bd4eaacc717e947de1ac8828e 100644 (file)
@@ -1 +1,2 @@
 r12-6647
+r12-6648
index c908719ec3afb4bf7a7fa48c6fb1bc44be5662b1..97d289409441a0cab580457734080aa6b5a42141 100644 (file)
@@ -2884,6 +2884,15 @@ from_chars_result from_chars_advanced(const char *first, const char *last,
   // If we called compute_float<binary_format<T>>(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<T>(pns, am); }
+
+  if((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) || am.power2 == binary_format<T>::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;
 }