https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108846
--- Comment #26 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-12 branch has been updated by Jonathan Wakely <[email protected]>: https://gcc.gnu.org/g:8ec265c1464dec74f98e6914cd164af5090a39ff commit r12-10250-g8ec265c1464dec74f98e6914cd164af5090a39ff Author: Jonathan Wakely <[email protected]> Date: Sat Feb 25 14:28:36 2023 +0000 libstdc++: Do not use memmove for 1-element ranges [PR108846] This avoids overwriting tail padding when algorithms like std::copy are used to write a single value through a pointer to a base subobject. The pointer arithmetic on a Base* is valid for N==1, but the copy/move operation needs to be done using assignment, not a memmove or memcpy of sizeof(Base) bytes. Instead of putting a check for N==1 in all of copy, copy_n, move etc. this adds it to the __copy_move and __copy_move_backward partial specializations used for trivially copyable types. When N==1 those partial specializations dispatch to new static member functions of the partial specializations for non-trivial types, so that a copy/move assignment is done appropriately for the _IsMove constant. libstdc++-v3/ChangeLog: PR libstdc++/108846 * include/bits/stl_algobase.h (__copy_move<false, false, RA>) Add __assign_one static member function. (__copy_move<true, false, RA>): Likewise. (__copy_move<IsMove, true, RA>): Do not use memmove for a single value. (__copy_move_backward<IsMove, true, RA>): Likewise. * testsuite/25_algorithms/copy/108846.cc: New test. * testsuite/25_algorithms/copy_backward/108846.cc: New test. * testsuite/25_algorithms/copy_n/108846.cc: New test. * testsuite/25_algorithms/move/108846.cc: New test. * testsuite/25_algorithms/move_backward/108846.cc: New test. (cherry picked from commit 822a11a1e642e0abe92a996e7033a5066905a447)
