Skip to content

Commit dc7a24f

Browse files
committed
Fix -Wconversion warnings with clang-20
1 parent 971cebe commit dc7a24f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/gtl/bits.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ GTL_FORCEINLINE uint32_t CountLeadingZeros64Slow(uint64_t n) {
266266
zeroes -= 8, n >>= 8;
267267
if (n >> 4)
268268
zeroes -= 4, n >>= 4;
269-
return (uint32_t)("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes);
269+
return static_cast<uint32_t>("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n]) + zeroes;
270270
}
271271

272272
GTL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
@@ -313,7 +313,7 @@ GTL_FORCEINLINE uint32_t CountLeadingZeros32Slow(uint64_t n) {
313313
zeroes -= 8, n >>= 8;
314314
if (n >> 4)
315315
zeroes -= 4, n >>= 4;
316-
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
316+
return static_cast<uint32_t>("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n]) + zeroes;
317317
}
318318

319319
GTL_FORCEINLINE uint32_t CountLeadingZeros32(uint32_t n) {
@@ -334,7 +334,7 @@ GTL_FORCEINLINE uint32_t CountLeadingZeros32(uint32_t n) {
334334
if (n == 0) {
335335
return 32;
336336
}
337-
return __builtin_clz(n);
337+
return static_cast<uint32_t>(__builtin_clz(n));
338338
#else
339339
return CountLeadingZeros32Slow(n);
340340
#endif
@@ -374,7 +374,7 @@ GTL_FORCEINLINE uint32_t CountTrailingZerosNonZero64(uint64_t n) {
374374
#elif defined(__GNUC__) || defined(__clang__)
375375
static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int)
376376
"__builtin_ctzll does not take 64-bit arg");
377-
return __builtin_ctzll(n);
377+
return static_cast<uint32_t>(__builtin_ctzll(n));
378378
#else
379379
return CountTrailingZerosNonZero64Slow(n);
380380
#endif
@@ -403,7 +403,7 @@ GTL_FORCEINLINE uint32_t CountTrailingZerosNonZero32(uint32_t n) {
403403
return (uint32_t)result;
404404
#elif defined(__GNUC__) || defined(__clang__)
405405
static_assert(sizeof(int) == sizeof(n), "__builtin_ctz does not take 32-bit arg");
406-
return __builtin_ctz(n);
406+
return static_cast<uint32_t>(__builtin_ctz(n));
407407
#else
408408
return CountTrailingZerosNonZero32Slow(n);
409409
#endif

0 commit comments

Comments
 (0)