[libcxx-commits] [libcxx] [libc++] Fix ambiguous call in {ranges, std}::find (PR #122641)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 26 09:49:32 PST 2025
================
@@ -38,29 +40,45 @@ _LIBCPP_BEGIN_NAMESPACE_STD
return __builtin_ctzll(__x);
}
+// A constexpr implementation for C++11 and later (using clang extensions for constexpr support)
+// Precondition: __t != 0 (the caller __countr_zero handles __t == 0 as a special case)
template <class _Tp>
-[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT {
-#if __has_builtin(__builtin_ctzg)
- return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
-#else // __has_builtin(__builtin_ctzg)
- if (__t == 0)
- return numeric_limits<_Tp>::digits;
- if (sizeof(_Tp) <= sizeof(unsigned int))
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __countr_zero_impl(_Tp __t) _NOEXCEPT {
+ _LIBCPP_ASSERT_INTERNAL(__t != 0, "__countr_zero_impl called with zero value");
+ static_assert(is_unsigned<_Tp>::value, "__countr_zero_impl only works with unsigned types");
+ // Use constexpr if as a C++17 extension for clang
----------------
ldionne wrote:
```suggestion
```
https://github.com/llvm/llvm-project/pull/122641
More information about the libcxx-commits
mailing list