bit_util: Protect Replicate from automatic up-casting

Recursive calls to `Replicate` beyond the first call might
cause an unintentional up-casting to an `int` type due
to `|` and `<<` operations on types such as `uint8_t` and `uint16_t`

This makes sure calls such as `Recursive<u8>` stay as the `u8` type
through-out.
This commit is contained in:
Wunkolo 2021-07-22 13:16:27 -07:00 committed by merry
parent f171ce7859
commit 46b8cfabc0

View file

@ -203,7 +203,7 @@ constexpr T Replicate(T value, size_t element_size) {
ASSERT_MSG(BitSize<T>() % element_size == 0, "bitsize of T not divisible by element_size"); ASSERT_MSG(BitSize<T>() % element_size == 0, "bitsize of T not divisible by element_size");
if (element_size == BitSize<T>()) if (element_size == BitSize<T>())
return value; return value;
return Replicate(value | (value << element_size), element_size * 2); return Replicate<T>(T(value | value << element_size), element_size * 2);
} }
template<typename T> template<typename T>