public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4819] libstdc++: Don't call 4-5 argument to_chars with chars_format{} Date: Wed, 21 Dec 2022 08:04:53 +0000 (GMT) [thread overview] Message-ID: <20221221080453.907193858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:3102b57f3105a301e54d7dc0586eb8e2b1724891 commit r13-4819-g3102b57f3105a301e54d7dc0586eb8e2b1724891 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Dec 21 09:04:06 2022 +0100 libstdc++: Don't call 4-5 argument to_chars with chars_format{} 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. Diff: --- libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc | 11 +++++++---- libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc | 13 ++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc index 735a507827a..32b328bbd7e 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc @@ -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 ); diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc b/libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc index db935377c1c..c51f802cf25 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc @@ -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)
reply other threads:[~2022-12-21 8:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221221080453.907193858D1E@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@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: linkBe 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).