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.
This commit is contained in:
parent
4ea128d5c7
commit
65857caee8
@ -801,14 +801,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));
|
||||
@ -853,7 +853,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;
|
||||
|
Loading…
Reference in New Issue
Block a user