https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94017
Bug ID: 94017 Summary: std::ranges::fill_n uses memset incorrectly Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: libstdc++ Assignee: ppalka at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <algorithm> int main() { int c[1] = { -1 }; std::ranges::fill(c, 'a'); if (*c != 'a') __builtin_abort(); } This fails, because it uses memset to set a single byte of the int. It also fails to compile with volatile input (related to PR 94013): #include <algorithm> int main() { volatile char c[1] = { -1 }; std::ranges::fill(c, 'a'); } In file included from /home/jwakely/gcc/10/include/c++/10.0.1/bits/ranges_algo.h:35, from /home/jwakely/gcc/10/include/c++/10.0.1/algorithm:64, from fill.cc:1: /home/jwakely/gcc/10/include/c++/10.0.1/bits/ranges_algobase.h: In instantiation of 'constexpr _Out std::ranges::__fill_n_fn::operator()(_Out, std::iter_difference_t<_Iter>, const _Tp&) const [with _Tp = char; _Out = volatile char*; std::iter_difference_t<_Iter> = long int]': /home/jwakely/gcc/10/include/c++/10.0.1/bits/ranges_algobase.h:555:27: required from 'constexpr _Out std::ranges::__fill_fn::operator()(_Out, _Sent, const _Tp&) const [with _Tp = char; _Out = volatile char*; _Sent = volatile char*]' /home/jwakely/gcc/10/include/c++/10.0.1/bits/ranges_algobase.h:576:16: required from 'constexpr std::ranges::borrowed_iterator_t<_Range> std::ranges::__fill_fn::operator()(_Range&&, const _Tp&) const [with _Tp = char; _Range = volatile char (&)[1]; std::ranges::borrowed_iterator_t<_Range> = volatile char*]' fill.cc:6:28: required from here /home/jwakely/gcc/10/include/c++/10.0.1/bits/ranges_algobase.h:522:23: error: invalid conversion from 'volatile void*' to 'void*' [-fpermissive] 522 | __builtin_memset(__first, static_cast<unsigned char>(__value), __n); | ^~~~~~~ | | | volatile void* <built-in>: note: initializing argument 1 of 'void* __builtin_memset(void*, int, long unsigned int)'