From 8697e134aeac0318e6686d785113f0763cbc3c1c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 16 Sep 2022 16:27:19 -0400 Subject: Fix signed bitwise operator operands --- .clang-tidy | 1 - include/chilbert/SmallBitVec.hpp | 6 +++--- include/chilbert/detail/BitVecMask.hpp | 8 ++++---- include/chilbert/detail/MultiBitVec.hpp | 6 +++--- include/chilbert/detail/operations.hpp | 4 ++-- test/test_bitvec.cpp | 2 +- test/test_utils.hpp | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ad6ec5b..a941ce1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,7 +27,6 @@ Checks: > -google-runtime-int, -google-runtime-references, -hicpp-explicit-conversions, - -hicpp-signed-bitwise, -llvm-header-guard, -llvmlibc-*, -misc-definitions-in-headers, diff --git a/include/chilbert/SmallBitVec.hpp b/include/chilbert/SmallBitVec.hpp index 599f789..4ddce46 100644 --- a/include/chilbert/SmallBitVec.hpp +++ b/include/chilbert/SmallBitVec.hpp @@ -45,8 +45,8 @@ public: class Mask { public: - void operator++() { m_mask <<= 1; } - void operator--() { m_mask >>= 1; } + void operator++() { m_mask <<= 1U; } + void operator--() { m_mask >>= 1U; } bool operator==(const Mask& mask) const { @@ -361,7 +361,7 @@ template <> void gray_code(SmallBitVec& value) { - value.rack() ^= (value.rack() >> 1); + value.rack() ^= (value.rack() >> 1U); } template <> diff --git a/include/chilbert/detail/BitVecMask.hpp b/include/chilbert/detail/BitVecMask.hpp index 03eaf5f..2d3466a 100644 --- a/include/chilbert/detail/BitVecMask.hpp +++ b/include/chilbert/detail/BitVecMask.hpp @@ -43,16 +43,16 @@ struct BitVecMask void operator++() { - if ((mask <<= 1) == 0) { - mask = 1; + if ((mask <<= 1U) == 0U) { + mask = 1U; ++rack; } } void operator--() { - if ((mask >>= 1) == 0) { - mask = Rack{1} << (bits_per_rack - 1); + if ((mask >>= 1U) == 0U) { + mask = Rack{1} << (bits_per_rack - 1U); --rack; } } diff --git a/include/chilbert/detail/MultiBitVec.hpp b/include/chilbert/detail/MultiBitVec.hpp index 573deef..2896c7c 100644 --- a/include/chilbert/detail/MultiBitVec.hpp +++ b/include/chilbert/detail/MultiBitVec.hpp @@ -354,9 +354,9 @@ gray_code(MultiBitVec& value) constexpr size_t left_shift = MultiBitVec::bits_per_rack - 1; for (size_t ri = 0; ri < value.num_racks(); ++ri) { - const size_t i = value.num_racks() - ri - 1; + const size_t i = value.num_racks() - ri - 1U; auto& rack = value.rack(i); - const auto t = rack & 1; + const auto t = rack & 1U; gray_code(rack); rack ^= (s << left_shift); s = t; @@ -377,7 +377,7 @@ gray_code_inv(MultiBitVec& value) auto& rack = value.rack(i); gray_code_inv(rack); rack ^= masks[s]; - s = rack & 1; + s = rack & 1U; } } diff --git a/include/chilbert/detail/operations.hpp b/include/chilbert/detail/operations.hpp index 7e846b3..398944f 100644 --- a/include/chilbert/detail/operations.hpp +++ b/include/chilbert/detail/operations.hpp @@ -145,7 +145,7 @@ template std::enable_if_t::value> gray_code(T& value) { - value ^= (value >> 1); + value ^= (value >> 1U); } /// Calculates the inverse Gray Code of `value` in place @@ -158,7 +158,7 @@ std::enable_if_t::value> gray_code_inv(T& value) { constexpr T shift_end = sizeof(T) * CHAR_BIT; - for (T shift = 1; shift < shift_end; shift <<= 1) { + for (T shift = 1U; shift < shift_end; shift <<= 1U) { value ^= (value >> shift); } } diff --git a/test/test_bitvec.cpp b/test/test_bitvec.cpp index a0e8b5b..c123212 100644 --- a/test/test_bitvec.cpp +++ b/test/test_bitvec.cpp @@ -251,7 +251,7 @@ test_find_first(Context&) v.reset(); v.set(i); for (size_t j = i + 1; j < N; ++j) { - v.set(j, rand() & 1); + v.set(j, rand() % 2); } assert(size_t(v.find_first()) == i + 1); } diff --git a/test/test_utils.hpp b/test/test_utils.hpp index 8c95fb4..3388552 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -49,7 +49,7 @@ make_random_bitvec(Context& ctx) { T v(N); for (size_t i = 0; i < N; ++i) { - v.set(i, ctx.dist(ctx.rng) & 1); + v.set(i, ctx.dist(ctx.rng) & 1U); } return v; } -- cgit v1.2.1