public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Don't call 4-5 argument to_chars with chars_format{}
Date: Wed, 21 Dec 2022 00:51:35 +0000	[thread overview]
Message-ID: <CACb0b4nZ3jZ2ZM20=Z0u856WxC5URR5K3yYKSrQNccnvg=ZoNg@mail.gmail.com> (raw)
In-Reply-To: <Y6F2oT1HjoJRCIL6@tucnak>

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
>


      reply	other threads:[~2022-12-21  0:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20  8:47 Jakub Jelinek
2022-12-21  0:51 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACb0b4nZ3jZ2ZM20=Z0u856WxC5URR5K3yYKSrQNccnvg=ZoNg@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).