https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121789
--- Comment #8 from Avi Kivity <avi at scylladb dot com> --- (In reply to Jonathan Wakely from comment #4) > > Or not comparing and calling memcpy() > > directly (which I see first compares against a bunch of small values before > > detecting zero, I can't make up my mind if it's better to check in libstdc++ > > or not). > > That would be undefined for the case of std::uninitialized_move_(it, it, > (T*)0) because calling memcpy with a null pointer is UB (at least for C++23 > and all previous standards). Right. memcpy() doesn't make an exception for n == 0. __builtin_memcpy() may though, if we want. > > So at a minimum we need to check __first != __last to ensure we don't call > memcpy with a null pointer, and if we have to check that anyway then my > thinking was that we might as well also avoid accessing out of bounds for > the buggy case where __last < __first. Agree.
