Fix warnings with clang-20/-Wconversion

This commit is contained in:
greg7mdp
2025-08-16 09:11:14 -04:00
parent c29681a777
commit d8f53a5947
+4 -4
View File
@@ -321,7 +321,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros32Slow(uint64_t n) {
if (n >> 16) zeroes -= 16, n >>= 16; if (n >> 16) zeroes -= 16, n >>= 16;
if (n >> 8) zeroes -= 8, n >>= 8; if (n >> 8) zeroes -= 8, n >>= 8;
if (n >> 4) zeroes -= 4, n >>= 4; if (n >> 4) zeroes -= 4, n >>= 4;
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes; return static_cast<uint32_t>("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n]) + zeroes;
} }
PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros32(uint32_t n) { PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros32(uint32_t n) {
@@ -343,7 +343,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros32(uint32_t n) {
if (n == 0) { if (n == 0) {
return 32; return 32;
} }
return __builtin_clz(n); return static_cast<uint32_t>(__builtin_clz(n));
#else #else
return CountLeadingZeros32Slow(n); return CountLeadingZeros32Slow(n);
#endif #endif
@@ -377,7 +377,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountTrailingZerosNonZero64(uint64_t n)
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int) static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int)
"__builtin_ctzll does not take 64-bit arg"); "__builtin_ctzll does not take 64-bit arg");
return __builtin_ctzll(n); return static_cast<uint32_t>(__builtin_ctzll(n));
#else #else
return CountTrailingZerosNonZero64Slow(n); return CountTrailingZerosNonZero64Slow(n);
#endif #endif
@@ -402,7 +402,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountTrailingZerosNonZero32(uint32_t n)
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
static_assert(sizeof(int) == sizeof(n), static_assert(sizeof(int) == sizeof(n),
"__builtin_ctz does not take 32-bit arg"); "__builtin_ctz does not take 32-bit arg");
return __builtin_ctz(n); return static_cast<uint32_t>(__builtin_ctz(n));
#else #else
return CountTrailingZerosNonZero32Slow(n); return CountTrailingZerosNonZero32Slow(n);
#endif #endif