From f073fe8ee5dcb0aa18c893198747062f2f51ab59 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 13 Oct 2022 14:12:39 -0700 Subject: Fix "unsafe narrowing" warnings in absl, 12/12. Addresses failures with the following, in some files: -Wshorten-64-to-32 -Wimplicit-int-conversion -Wsign-compare -Wsign-conversion -Wtautological-unsigned-zero-compare (This specific CL enables these warnings and fixes the remaining known issues.) Bug: chromium:1292951 PiperOrigin-RevId: 480981210 Change-Id: I92d5023c6833e24d6aa29b10d433116329972f41 --- absl/strings/charconv.cc | 8 ++++++-- absl/strings/internal/cord_internal.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'absl/strings') diff --git a/absl/strings/charconv.cc b/absl/strings/charconv.cc index c08623c4..69d420bc 100644 --- a/absl/strings/charconv.cc +++ b/absl/strings/charconv.cc @@ -298,7 +298,9 @@ struct CalculatedFloat { // minus the number of leading zero bits.) int BitWidth(uint128 value) { if (Uint128High64(value) == 0) { - return bit_width(Uint128Low64(value)); + // This static_cast is only needed when using a std::bit_width() + // implementation that does not have the fix for LWG 3656 applied. + return static_cast(bit_width(Uint128Low64(value))); } return 128 - countl_zero(Uint128High64(value)); } @@ -580,7 +582,9 @@ CalculatedFloat CalculateFromParsedHexadecimal( const strings_internal::ParsedFloat& parsed_hex) { uint64_t mantissa = parsed_hex.mantissa; int exponent = parsed_hex.exponent; - int mantissa_width = bit_width(mantissa); + // This static_cast is only needed when using a std::bit_width() + // implementation that does not have the fix for LWG 3656 applied. + int mantissa_width = static_cast(bit_width(mantissa)); const int shift = NormalizedShiftSize(mantissa_width, exponent); bool result_exact; exponent += shift; diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h index eca747c8..fcca3a28 100644 --- a/absl/strings/internal/cord_internal.h +++ b/absl/strings/internal/cord_internal.h @@ -591,7 +591,7 @@ class InlineData { // See the documentation on 'as_chars()' for more information and examples. void set_inline_size(size_t size) { ABSL_ASSERT(size <= kMaxInline); - tag() = static_cast(size << 1); + tag() = static_cast(size << 1); } // Compares 'this' inlined data with rhs. The comparison is a straightforward -- cgit v1.2.3