Skip to content

Commit

Permalink
BitHacks: remove assert(), fixes zxing-cpp#756
Browse files Browse the repository at this point in the history
This is basically a regression introduced into the MSVC code path in
zxing-cpp@c661a3f
but the problem was already present in a non-gcc-non-msvc code path.
  • Loading branch information
axxel committed Mar 30, 2024
1 parent 75ae138 commit 6cd099e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/BitHacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ inline int NumberOfLeadingZeros(T x)
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
inline int NumberOfTrailingZeros(T v)
{
assert(v != 0);
#ifdef __cpp_lib_bitops
return std::countr_zero(static_cast<std::make_unsigned_t<T>>(v));
#else
if constexpr (sizeof(v) <= 4) {
static_assert(sizeof(v) == 4, "NumberOfTrailingZeros not implemented for 8 and 16 bit ints.");
#ifdef ZX_HAS_GCC_BUILTINS
return __builtin_ctz(v);
return v == 0 ? 32 : __builtin_ctz(v);
#elif defined(ZX_HAS_MSC_BUILTINS)
unsigned long where;
if (_BitScanForward(&where, v))
Expand All @@ -108,7 +107,7 @@ inline int NumberOfTrailingZeros(T v)
#endif
} else {
#ifdef ZX_HAS_GCC_BUILTINS
return __builtin_ctzll(v);
return v == 0 ? 64 : __builtin_ctzll(v);
#else // including ZX_HAS_MSC_BUILTINS
int n = NumberOfTrailingZeros(static_cast<uint32_t>(v));
if (n == 32)
Expand Down

0 comments on commit 6cd099e

Please sign in to comment.