https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121905
Bug ID: 121905 Summary: std::rotate optimizations for POD types and random access iterators Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- For the __rotate overload taking random access iterators, check that this optimizes to memmove for contiguous iterators: if (__is_pod(_ValueType) && __k == 1) { _ValueType __t = _GLIBCXX_MOVE(*__p); _GLIBCXX_MOVE3(__p + _Distance(1), __p + __n, __p); __p[_Distance(__n - 1)] = _GLIBCXX_MOVE(__t); return __ret; } and this one: if (__is_pod(_ValueType) && __k == 1) { _RandomAccessIterator __p_n_1 = __p + _Distance(__n - 1); _ValueType __t = _GLIBCXX_MOVE(*__p_n_1); _GLIBCXX_MOVE_BACKWARD3(__p, __p_n_1, __p + __n); *__p = _GLIBCXX_MOVE(__t); return __ret; } Is there any point using std::move here when it's a POD anyway? Removing the _GLIBCXX_MOVE uses and changing _GLIBCXX_MOVE3 and _GLIBCXX_MOVE_BACKWARD3 to std::copy and std::copy_backward would make the code easier to read. We should replace __is_pod with more precise checks (trivially copyable + trivially assignable?) And check ranges::rotate too.