Avoid libgcc -NaN narrowing bug
authorBenjamin Barenblat <bbaren@google.com>
Tue, 9 Feb 2021 19:41:06 +0000 (19:41 +0000)
committerBenjamin Barenblat <bbaren@debian.org>
Tue, 9 Feb 2021 19:41:06 +0000 (19:41 +0000)
Forwarded: yes
Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/1bae23e32ba1f1af7c7d1488a69a351ec96dc98d

When testing -NaN parsing, avoid narrowing -NaN from double to float. This
avoids a bug in libgcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98251).

The author works at Google. Upstream applied this patch as Piper revision
347654751 and exported it to GitHub; the Applied-Upstream URL above points to
the exported commit.

Gbp-Pq: Name nan-narrowing.diff

absl/strings/charconv_test.cc

index 9090e9c89c507d3a34b0e5a771bcb9e44d6cbe65..b83de5a0ba26dae202fe212491614b830f28e8e4 100644 (file)
@@ -653,7 +653,9 @@ TEST(FromChars, NaNFloats) {
                      negative_from_chars_float);
     EXPECT_TRUE(std::signbit(negative_from_chars_float));
     EXPECT_FALSE(Identical(negative_from_chars_float, from_chars_float));
-    from_chars_float = std::copysign(from_chars_float, -1.0);
+    // Use the (float, float) overload of std::copysign to prevent narrowing;
+    // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98251.
+    from_chars_float = std::copysign(from_chars_float, -1.0f);
     EXPECT_TRUE(Identical(negative_from_chars_float, from_chars_float));
   }
 }