https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86471
--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Matt Bentley from comment #14) > (In reply to Matt Bentley from comment #13) > > (In reply to Jonathan Wakely from comment #12) > > > Also you're doing a reinterpret_cast from an arbitrary iterator type, > > > which > > > is not necessarily a pointer, or even a random access iterator. > > > > > > Since you don't have a copyright assignment in place please leave the > > > patch > > > to us, this is less than helpful :-) > > > > Well it's more that you're doing- I'm thinking about how to actually fix it, with a patch that works and could be accepted into libstdc++. Look at how this exact problem is already solved elsewhere in the same file. All the algorithms that dispatch to a __builtin_memxxx function use similar techniques, detecting when the iterators are pointers for a start. And see https://gcc.gnu.org/contribute.html#legal for why code pasted into bugzilla without the necessary paperwork is unhelpful (and possibly even counter-productive if we end up having to re-invent the same wheel without using your code). > at any rate, the issue you've noted is > > easily bypassed by changing the "reinterpret_cast<void *>(__first)" to > > "reinterpret_cast<void *>(&*(__first))". > > Cheers. > > My bad, I missed the point about the memory not necessarily being contiguous. Indeed. It's a forward iterator. Even a random access iterator doesn't guarantee you can do that (e.g. std::deque::iterator is random access but not contiguous).