diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h index 2091c3662d507..4de142b56165b 100644 --- a/libc/src/__support/CPP/bit.h +++ b/libc/src/__support/CPP/bit.h @@ -78,7 +78,7 @@ template >> return 0; // Bisection method. unsigned zero_bits = 0; - T shift = cpp::numeric_limits::digits >> 1; + unsigned shift = cpp::numeric_limits::digits >> 1; T mask = cpp::numeric_limits::max() >> shift; while (shift) { if ((value & mask) == 0) { @@ -115,7 +115,8 @@ template >> return cpp::numeric_limits::digits; // Bisection method. unsigned zero_bits = 0; - for (T shift = cpp::numeric_limits::digits >> 1; shift; shift >>= 1) { + for (unsigned shift = cpp::numeric_limits::digits >> 1; shift; + shift >>= 1) { T tmp = value >> shift; if (tmp) value = tmp; diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h index f72b995f8788d..cfd495c586185 100644 --- a/libc/src/__support/UInt.h +++ b/libc/src/__support/UInt.h @@ -903,6 +903,7 @@ template <> class numeric_limits> { return UInt<128>({0xffff'ffff'ffff'ffff, 0xffff'ffff'ffff'ffff}); } LIBC_INLINE static constexpr UInt<128> min() { return UInt<128>(0); } + LIBC_INLINE_VAR static constexpr int digits = 128; }; template <> class numeric_limits> { @@ -913,6 +914,7 @@ template <> class numeric_limits> { LIBC_INLINE static constexpr Int<128> min() { return Int<128>({0, 0x8000'0000'0000'0000}); } + LIBC_INLINE_VAR static constexpr int digits = 128; }; // Provides is_integral of U/Int<128>, U/Int<192>, U/Int<256>. diff --git a/libc/test/src/__support/CPP/bit_test.cpp b/libc/test/src/__support/CPP/bit_test.cpp index b7cd99d169fc5..fef551bc1f0e2 100644 --- a/libc/test/src/__support/CPP/bit_test.cpp +++ b/libc/test/src/__support/CPP/bit_test.cpp @@ -16,7 +16,11 @@ namespace LIBC_NAMESPACE::cpp { using UnsignedTypes = testing::TypeList; + unsigned long, unsigned long long, +#if defined(__SIZEOF_INT128__) + __uint128_t, +#endif + cpp::UInt<128>>; TYPED_TEST(LlvmLibcBitTest, HasSingleBit, UnsignedTypes) { EXPECT_FALSE(has_single_bit(T(0)));