public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-114821-4-PW2qqIIw3i@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-114821-4@http.gcc.gnu.org/bugzilla/> 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.
next prev parent reply other threads:[~2024-04-23 8:30 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-23 8:14 [Bug libstdc++/114821] New: " hubicka at gcc dot gnu.org 2024-04-23 8:30 ` redi at gcc dot gnu.org [this message] 2024-04-23 8:52 ` [Bug libstdc++/114821] " hubicka at gcc dot gnu.org 2024-04-23 10:41 ` redi at gcc dot gnu.org 2024-04-23 10:51 ` redi at gcc dot gnu.org 2024-04-23 11:01 ` redi at gcc dot gnu.org 2024-04-23 12:08 ` hubicka at gcc dot gnu.org 2024-04-23 12:33 ` redi at gcc dot gnu.org 2024-04-23 12:38 ` hubicka at gcc dot gnu.org 2024-04-23 12:41 ` hubicka at gcc dot gnu.org 2024-04-23 12:42 ` redi at gcc dot gnu.org 2024-04-23 13:11 ` redi at gcc dot gnu.org 2024-04-23 15:53 ` redi at gcc dot gnu.org 2024-04-24 14:23 ` hubicka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-114821-4-PW2qqIIw3i@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).