https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101608
Bug ID: 101608
Summary: ranges::fill/fill_n missing
std::is_constant_evaluated() condition for
__builtin_memset
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
ranges_algobase.h#L529:
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;
}
We should ensure that std::is_constant_evaluated() is false before calling
__builtin_memset since it is not usable in constexpr contexts.
#include <algorithm>
constexpr auto unused = [] {
std::array<unsigned char, 5> r{};
std::ranges::fill(r, 0);
return 0;
}();
https://godbolt.org/z/bnYxY78o8