Skip to content

Commit 545d1eb

Browse files
committed
[UPSTREAM] Use if constexpr to silence compiler warnings
This only matters downstream - in the CHERI target we specialize this function and calling it from the specialized version triggers shift count warnings in the else case. These warnings appear to not trigger when called directly. Fix this by using if constexpr which is safe since the functions are C++20 only.
1 parent 7815ae3 commit 545d1eb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

libcxx/include/__bit/countr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) n
3939
if (__t == 0)
4040
return numeric_limits<_Tp>::digits;
4141

42-
if (sizeof(_Tp) <= sizeof(unsigned int))
42+
if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
4343
return std::__libcpp_ctz(static_cast<unsigned int>(__t));
44-
else if (sizeof(_Tp) <= sizeof(unsigned long))
44+
else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
4545
return std::__libcpp_ctz(static_cast<unsigned long>(__t));
46-
else if (sizeof(_Tp) <= sizeof(unsigned long long))
46+
else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long))
4747
return std::__libcpp_ctz(static_cast<unsigned long long>(__t));
4848
else {
4949
int __ret = 0;

libcxx/include/__bit/popcount.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popco
3636

3737
template <__libcpp_unsigned_integer _Tp>
3838
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept {
39-
if (sizeof(_Tp) <= sizeof(unsigned int))
39+
if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
4040
return std::__libcpp_popcount(static_cast<unsigned int>(__t));
41-
else if (sizeof(_Tp) <= sizeof(unsigned long))
41+
else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
4242
return std::__libcpp_popcount(static_cast<unsigned long>(__t));
43-
else if (sizeof(_Tp) <= sizeof(unsigned long long))
43+
else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long))
4444
return std::__libcpp_popcount(static_cast<unsigned long long>(__t));
4545
else {
4646
int __ret = 0;

0 commit comments

Comments
 (0)