https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114821
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Using memcpy on any std::pair is undefined behaviour because it's not trivially
copyable.
That's not because it has a copy constructor, its copy constructor is defaulted
and so trivial if the data members are trivially copy constructible:
constexpr pair(const pair&) = default; ///< Copy constructor
It's because it has a non-trivial assignment operator:
/// Copy assignment operator
constexpr pair&
operator=(const pair& __p)
noexcept(_S_nothrow_assignable<const _T1&, const _T2&>())
requires (_S_assignable<const _T1&, const _T2&>())
{
first = __p.first;
second = __p.second;
return *this;
}
I think this exact point was discussed when Marc introduced the relocate
optimizations. We could maybe cheat and say that we know it's safe to memcpy
std::pair<int, int> even though the language says it's undefined, because we
know what our std::pair implementation looks like.