[libc-commits] [libc] [libc][stdbit] implement stdc_bit_floor (C23) (PR #84233)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Wed Mar 6 12:56:40 PST 2024


================
@@ -169,7 +169,7 @@ template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
 [[nodiscard]] LIBC_INLINE constexpr T bit_floor(T value) {
   if (!value)
     return 0;
-  return T(1) << (cpp::bit_width(value) - 1);
+  return static_cast<T>(T(1) << (cpp::bit_width(value) - 1));
----------------
nickdesaulniers wrote:

Note to reviewers: without this change, I observe an integer truncation warning (promoted to error) for types smaller than int. They undergo implicit promotion from the binary operator `<<`.

https://github.com/llvm/llvm-project/pull/84233


More information about the libc-commits mailing list