public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-9798] libstdc++: Avoid implicit narrowing from uint128_t [PR104859] Date: Thu, 7 Apr 2022 19:36:46 +0000 (GMT) [thread overview] Message-ID: <20220407193646.521773858D28@sourceware.org> (raw) https://gcc.gnu.org/g:c859c99a85b8743b2c1edc097c6f6406de337f45 commit r11-9798-gc859c99a85b8743b2c1edc097c6f6406de337f45 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Mar 9 18:48:52 2022 -0500 libstdc++: Avoid implicit narrowing from uint128_t [PR104859] We need to be explicit about narrowing conversions from uint128_t since, on targets that lack __int128, this type is defined as an integer-class type that is only _explicitly_ convertible to the builtin integer types. This issue was latent until r12-7563-ge32869a17b788b made the frontend correctly reject explicit conversion functions during (dependent) copy-initialization. PR libstdc++/104859 libstdc++-v3/ChangeLog: * src/c++17/floating_to_chars.cc (__floating_to_chars_hex): Be explicit when narrowing the shifted effective_mantissa, since it may have an integer-class type. (cherry picked from commit 65857caee8ccfac5007a9fd0e5f18cce5e5fe934) Diff: --- libstdc++-v3/src/c++17/floating_to_chars.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc index 44f547a77b4..2545022ced6 100644 --- a/libstdc++-v3/src/c++17/floating_to_chars.cc +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc @@ -799,14 +799,14 @@ template<typename T> char leading_hexit; if constexpr (has_implicit_leading_bit) { - const unsigned nibble = effective_mantissa >> rounded_mantissa_bits; + const auto nibble = unsigned(effective_mantissa >> rounded_mantissa_bits); __glibcxx_assert(nibble <= 2); leading_hexit = '0' + nibble; effective_mantissa &= ~(mantissa_t{0b11} << rounded_mantissa_bits); } else { - const unsigned nibble = effective_mantissa >> (rounded_mantissa_bits-4); + const auto nibble = unsigned(effective_mantissa >> (rounded_mantissa_bits-4)); __glibcxx_assert(nibble < 16); leading_hexit = "0123456789abcdef"[nibble]; effective_mantissa &= ~(mantissa_t{0b1111} << (rounded_mantissa_bits-4)); @@ -847,7 +847,7 @@ template<typename T> while (effective_mantissa != 0) { nibble_offset -= 4; - const unsigned nibble = effective_mantissa >> nibble_offset; + const auto nibble = unsigned(effective_mantissa >> nibble_offset); __glibcxx_assert(nibble < 16); *first++ = "0123456789abcdef"[nibble]; ++written_hexits;
reply other threads:[~2022-04-07 19:36 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=20220407193646.521773858D28@sourceware.org \ --to=ppalka@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).