if (__n <= 0)
return __first;
- // TODO: Generalize this optimization to contiguous iterators.
- if constexpr (is_pointer_v<_Out>
- // Note that __is_byte already implies !is_volatile.
- && __is_byte<remove_pointer_t<_Out>>::__value
- && integral<_Tp>)
- {
- __builtin_memset(__first, static_cast<unsigned char>(__value), __n);
- return __first + __n;
- }
- else if constexpr (is_scalar_v<_Tp>)
+ if constexpr (is_scalar_v<_Tp>)
{
+ // TODO: Generalize this optimization to contiguous iterators.
+ if constexpr (is_pointer_v<_Out>
+ // Note that __is_byte already implies !is_volatile.
+ && __is_byte<remove_pointer_t<_Out>>::__value
+ && integral<_Tp>)
+ {
+#ifdef __cpp_lib_is_constant_evaluated
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ __builtin_memset(__first,
+ static_cast<unsigned char>(__value),
+ __n);
+ return __first + __n;
+ }
+ }
+
const auto __tmp = __value;
for (; __n > 0; --__n, (void)++__first)
*__first = __tmp;
}
}
+template<typename T>
constexpr bool
test02()
{
bool ok = true;
- int x[6] = { 1, 2, 3, 4, 5, 6 };
+ T x[6] = { 1, 2, 3, 4, 5, 6 };
const int y[6] = { 1, 2, 3, 4, 5, 6 };
const int z[6] = { 17, 17, 17, 4, 5, 6 };
main()
{
test01();
- static_assert(test02());
+ static_assert(test02<int>());
+ static_assert(test02<unsigned char>()); // PR libstdc++/101608
}