Skip to content

Conversation

philnik777
Copy link
Contributor

The builtins already diagnose types other than unsigned integers, so there is no point in static_asserting that again.

@ldionne ldionne marked this pull request as ready for review October 6, 2025 15:30
@ldionne ldionne requested a review from a team as a code owner October 6, 2025 15:30
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

The builtins already diagnose types other than unsigned integers, so there is no point in static_asserting that again.


Full diff: https://github.com/llvm/llvm-project/pull/161487.diff

3 Files Affected:

  • (modified) libcxx/include/__bit/countl.h (-1)
  • (modified) libcxx/include/__bit/countr.h (-1)
  • (modified) libcxx/include/__bit/popcount.h (-1)
diff --git a/libcxx/include/__bit/countl.h b/libcxx/include/__bit/countl.h
index 29b01277fb0eb..c95828f58d61a 100644
--- a/libcxx/include/__bit/countl.h
+++ b/libcxx/include/__bit/countl.h
@@ -24,7 +24,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT {
-  static_assert(__is_unsigned_integer_v<_Tp>, "__countl_zero requires an unsigned integer type");
   return __builtin_clzg(__t, numeric_limits<_Tp>::digits);
 }
 
diff --git a/libcxx/include/__bit/countr.h b/libcxx/include/__bit/countr.h
index 4de887ad4f67c..16f689d6da383 100644
--- a/libcxx/include/__bit/countr.h
+++ b/libcxx/include/__bit/countr.h
@@ -24,7 +24,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __countr_zero(_Tp __t) _NOEXCEPT {
-  static_assert(__is_unsigned_integer_v<_Tp>, "__countr_zero only works with unsigned types");
   return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
 }
 
diff --git a/libcxx/include/__bit/popcount.h b/libcxx/include/__bit/popcount.h
index 8d9ba09938482..d104c8e8f0a98 100644
--- a/libcxx/include/__bit/popcount.h
+++ b/libcxx/include/__bit/popcount.h
@@ -23,7 +23,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
-  static_assert(__is_unsigned_integer_v<_Tp>, "__popcount only works with unsigned types");
   return __builtin_popcountg(__t);
 }
 

@philnik777 philnik777 merged commit b88af66 into llvm:main Oct 7, 2025
73 of 82 checks passed
@philnik777 philnik777 deleted the bit_funcs_remove_static_assert branch October 7, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants