[libcxx-commits] [libcxx] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (PR #122410)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 29 08:42:52 PST 2025


================
@@ -23,6 +26,11 @@ class __bit_iterator;
 template <class, class = void>
 struct __size_difference_type_traits;
 
+template <class _StoragePointer,
+          __enable_if_t<is_unsigned<typename pointer_traits<_StoragePointer>::element_type>::value, int> = 0>
----------------
ldionne wrote:

Since this `enable_if` is more like a sanity check than a real `if-else` branch (since there's no `else` overload), I would move the check for `is_unsigned` to a `static_assert` inside `__fill_masked_range`. That will simplify the (re)declaration of this function and reduce the dependencies you need to add to this forward-declaration header.

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


More information about the libcxx-commits mailing list