From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 47330385840E; Wed, 9 Mar 2022 23:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47330385840E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-7571] libstdc++: Avoid implicit narrowing from uint128_t [PR104859] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 4ea128d5c740e4e8c2e7b70de3a90435035eb863 X-Git-Newrev: 65857caee8ccfac5007a9fd0e5f18cce5e5fe934 Message-Id: <20220309234954.47330385840E@sourceware.org> Date: Wed, 9 Mar 2022 23:49:54 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2022 23:49:54 -0000 https://gcc.gnu.org/g:65857caee8ccfac5007a9fd0e5f18cce5e5fe934 commit r12-7571-g65857caee8ccfac5007a9fd0e5f18cce5e5fe934 Author: Patrick Palka 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. 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 5825e661bf4..66bd457cbe2 100644 --- a/libstdc++-v3/src/c++17/floating_to_chars.cc +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc @@ -801,14 +801,14 @@ template 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)); @@ -853,7 +853,7 @@ template 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;