]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Don't call 4-5 argument to_chars with chars_format{}
authorJakub Jelinek <jakub@redhat.com>
Wed, 21 Dec 2022 08:04:06 +0000 (09:04 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 21 Dec 2022 08:04:06 +0000 (09:04 +0100)
In Fedora build libstdc++.so is built with assertions enabled and
FAIL: 20_util/to_chars/float128_c++23.cc execution test
was failing on all arches.  The problem is that it called 5 argument version
of to_chars with chars_format{}, which C++ says is invalid:
http://eel.is/c++draft/charconv.to.chars#12
Preconditions: fmt has the value of one of the enumerators of chars_format.

The following patch fixes it by skipping the second part of the test
which needs the 5 argument to_chars for chars_format{}, but because
it is strictly speaking invalid also for 4 argument to_chars, it uses
3 argument to_chars instead of 4 argument to_chars with last argument
chars_format{}.

2022-12-21  Jakub Jelinek  <jakub@redhat.com>

* testsuite/20_util/to_chars/float16_c++23.cc (test): Use 3 argument
std::to_chars if fmt is std::chars_format{}, rather than 4 argument.
* testsuite/20_util/to_chars/float128_c++23.cc (test): Likewise, and
skip second part of testing that requires 5 argument std::to_chars.

libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc

index 735a507827a29b402d44f961c81e53f079307afd..32b328bbd7e0f3945e6120bd5b8744cd0276c978 100644 (file)
@@ -60,7 +60,9 @@ test(std::chars_format fmt = std::chars_format{})
   char str1[10000], str2[10000];
   for (auto u : tests)
     {
-      auto [ptr1, ec1] = std::to_chars(str1, str1 + sizeof(str1), u, fmt);
+      auto [ptr1, ec1] = (fmt == std::chars_format{}
+                         ? std::to_chars(str1, str1 + sizeof(str1), u)
+                         : std::to_chars(str1, str1 + sizeof(str1), u, fmt));
       VERIFY( ec1 == std::errc() );
 //    std::cout << u << ' ' << std::string_view (str1, ptr1) << '\n';
       if (fmt == std::chars_format::fixed)
@@ -77,13 +79,14 @@ test(std::chars_format fmt = std::chars_format{})
       VERIFY( ec4 == std::errc() && ptr4 == ptr1 );
       VERIFY( u == v );
 
+      if (fmt == std::chars_format{})
+       continue;
+
       auto [ptr5, ec5] = std::to_chars(str1, str1 + sizeof(str1), u, fmt, 90);
       VERIFY( ec5 == std::errc() );
 //    std::cout << u << ' ' << std::string_view (str1, ptr5) << '\n';
       v = 4.0f128;
-      auto [ptr6, ec6] = std::from_chars(str1, ptr5, v,
-                                        fmt == std::chars_format{}
-                                        ? std::chars_format::general : fmt);
+      auto [ptr6, ec6] = std::from_chars(str1, ptr5, v, fmt);
       VERIFY( ec6 == std::errc() && ptr6 == ptr5 );
       if (fmt == std::chars_format::fixed && u > 0.0f128 && u < 0.000001f128)
        VERIFY( v == 0.0 );
index db935377c1c087c06a1a3f4e11f6016809bb9d47..c51f802cf25f48577d0b574ecc51806b7244002a 100644 (file)
@@ -36,9 +36,16 @@ test(std::chars_format fmt = std::chars_format{})
   for (int i = 0; i <= (unsigned short) ~0; ++i)
     {
       u.s = i;
-      auto [ptr1, ec1] = std::to_chars(str1, str1 + sizeof(str1), u.f, fmt);
-      auto [ptr2, ec2] = std::to_chars(str2, str2 + sizeof(str2), std::float32_t(u.f), fmt);
-      VERIFY( ec1 == std::errc() && ec2 == std::errc());
+      auto [ptr1, ec1] = (fmt == std::chars_format{}
+                         ? std::to_chars(str1, str1 + sizeof(str1), u.f)
+                         : std::to_chars(str1, str1 + sizeof(str1), u.f,
+                                         fmt));
+      auto [ptr2, ec2] = (fmt == std::chars_format{}
+                         ? std::to_chars(str2, str2 + sizeof(str2),
+                                         std::float32_t(u.f))
+                         : std::to_chars(str2, str2 + sizeof(str2),
+                                         std::float32_t(u.f), fmt));
+      VERIFY( ec1 == std::errc() && ec2 == std::errc() );
 //    std::cout << i << ' ' << std::string_view (str1, ptr1)
 //     << '\t' << std::string_view (str2, ptr2) << '\n';
       if (fmt == std::chars_format::fixed)
This page took 0.064011 seconds and 5 git commands to generate.