From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8B9553858D3C; Tue, 23 Apr 2024 08:30:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B9553858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713861003; bh=DLXW5W8CvqG/2b8fErSP+vZIJM9ggtTsuv1/+M+R7Kc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tjVvPRU6AohIN6i97mF289HKEyzrIfS3RxKCk+jrd1plZNfjySTmQMFtlEi88/gAX XfXEYONfMJc3Zu98ZPhgzbda8vPbJnZwG8jUfeeoYu1jWKuudYp2XXYW6boe3ltwRF a6E73r7RKSswpWOulaJXTDu5ItaTntuKyAETzwI4= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114821] _M_realloc_append should use memcpy instead of loop to copy data when possible Date: Tue, 23 Apr 2024 08:30:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114821 --- Comment #1 from Jonathan Wakely --- Using memcpy on any std::pair is undefined behaviour because it's not trivi= ally copyable.=20 That's not because it has a copy constructor, its copy constructor is defau= lted and so trivial if the data members are trivially copy constructible: constexpr pair(const pair&) =3D default; ///< Copy constructor It's because it has a non-trivial assignment operator: /// Copy assignment operator constexpr pair& operator=3D(const pair& __p) noexcept(_S_nothrow_assignable()) requires (_S_assignable()) { first =3D __p.first; second =3D __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 even though the language says it's undefined, because we know what our std::pair implementation looks like.=