libstdc++: Don't call 4-5 argument to_chars with chars_format{}

Message ID Y6F2oT1HjoJRCIL6@tucnak
State Unresolved
Headers
Series libstdc++: Don't call 4-5 argument to_chars with chars_format{} |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Dec. 20, 2022, 8:47 a.m. UTC
  Hi!

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{}.

Bootstrapped/regtested on {x86_64,i686,aarch64,powerpc64le,s390x}-linux, ok
for trunk?

2022-12-20  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.


	Jakub
  

Comments

Jonathan Wakely Dec. 21, 2022, 12:51 a.m. UTC | #1
On Tue, 20 Dec 2022 at 08:47, Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> 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{}.
>
> Bootstrapped/regtested on {x86_64,i686,aarch64,powerpc64le,s390x}-linux, ok
> for trunk?

OK, thanks.

>
> 2022-12-20  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/float16_c++23.cc.jj 2022-11-01 22:45:50.653626818 +0100
> +++ libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc    2022-12-19 16:23:28.989733811 +0100
> @@ -36,9 +36,16 @@ test(std::chars_format fmt = std::chars_
>    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)
> --- libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc.jj        2022-11-25 22:23:44.540104246 +0100
> +++ libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc   2022-12-19 16:24:49.142571475 +0100
> @@ -60,7 +60,9 @@ test(std::chars_format fmt = std::chars_
>    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_
>        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 );
>
>         Jakub
>
  

Patch

--- libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc.jj	2022-11-01 22:45:50.653626818 +0100
+++ libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc	2022-12-19 16:23:28.989733811 +0100
@@ -36,9 +36,16 @@  test(std::chars_format fmt = std::chars_
   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)
--- libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc.jj	2022-11-25 22:23:44.540104246 +0100
+++ libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc	2022-12-19 16:24:49.142571475 +0100
@@ -60,7 +60,9 @@  test(std::chars_format fmt = std::chars_
   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_
       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 );