mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
[bits] Add tests for return types
With gcc <= 12, std::bit_width<T>() returns T, not int, so make sure the absl:: equivalents return the correct type. https://github.com/abseil/abseil-cpp/issues/1890 PiperOrigin-RevId: 760612745 Change-Id: Ibbbe6eaa1aab677ecd747cf40765f6443eefe628
This commit is contained in:
committed by
Copybara-Service
parent
41a1f434d4
commit
fc0b7a083b
@@ -26,16 +26,37 @@ namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace {
|
||||
|
||||
template <typename IntT>
|
||||
class UnsignedIntegerTypesTest : public ::testing::Test {};
|
||||
template <typename IntT>
|
||||
class IntegerTypesTest : public ::testing::Test {};
|
||||
|
||||
using UnsignedIntegerTypes =
|
||||
::testing::Types<uint8_t, uint16_t, uint32_t, uint64_t>;
|
||||
using OneByteIntegerTypes = ::testing::Types<
|
||||
unsigned char,
|
||||
uint8_t
|
||||
>;
|
||||
|
||||
TYPED_TEST_SUITE(UnsignedIntegerTypesTest, UnsignedIntegerTypes);
|
||||
TYPED_TEST_SUITE(IntegerTypesTest, OneByteIntegerTypes);
|
||||
|
||||
TYPED_TEST(UnsignedIntegerTypesTest, ReturnTypes) {
|
||||
using UIntType = TypeParam;
|
||||
|
||||
static_assert(std::is_same_v<decltype(byteswap(UIntType{0})), UIntType>);
|
||||
static_assert(std::is_same_v<decltype(rotl(UIntType{0}, 0)), UIntType>);
|
||||
static_assert(std::is_same_v<decltype(rotr(UIntType{0}, 0)), UIntType>);
|
||||
static_assert(std::is_same_v<decltype(countl_zero(UIntType{0})), int>);
|
||||
static_assert(std::is_same_v<decltype(countl_one(UIntType{0})), int>);
|
||||
static_assert(std::is_same_v<decltype(countr_zero(UIntType{0})), int>);
|
||||
static_assert(std::is_same_v<decltype(countr_one(UIntType{0})), int>);
|
||||
static_assert(std::is_same_v<decltype(popcount(UIntType{0})), int>);
|
||||
static_assert(std::is_same_v<decltype(bit_ceil(UIntType{0})), UIntType>);
|
||||
static_assert(std::is_same_v<decltype(bit_floor(UIntType{0})), UIntType>);
|
||||
static_assert(std::is_same_v<decltype(bit_width(UIntType{0})), int>);
|
||||
}
|
||||
|
||||
TYPED_TEST(IntegerTypesTest, HandlesTypes) {
|
||||
using UIntType = TypeParam;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user