public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jchl at arista dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98835] New: False positive -Wclass-memaccess with class with ref-qualified copy-assignment operator Date: Tue, 26 Jan 2021 09:33:26 +0000 [thread overview] Message-ID: <bug-98835-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98835 Bug ID: 98835 Summary: False positive -Wclass-memaccess with class with ref-qualified copy-assignment operator Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jchl at arista dot com Target Milestone: --- Consider the following code: #include <type_traits> #include <cstring> class Good { public: Good & operator=(Good const &) = default; }; class Bad { public: Bad & operator=(Bad const &) & = default; }; template<typename T> void test() { static_assert(std::is_trivially_copyable_v<T>); T value1; T value2; std::memcpy(&value1, &value2, sizeof(T)); } int main() { test<Good>(); test<Bad>(); } [See: https://godbolt.org/z/4vj9GT ] GCC trunk on x86_64 incorrectly gives the following warning: <source>: In instantiation of 'void test() [with T = Bad]': <source>:24:15: required from here <source>:19:16: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class Bad' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess] 19 | std::memcpy(&value1, &value2, sizeof(T)); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since both Good and Bad have trivial copy-assignment operators and are trivially copyable, both types are eligible to be memcpy'd; the ref-qualification of the assignment operator shouldn't be relevant.
next reply other threads:[~2021-01-26 9:33 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-26 9:33 jchl at arista dot com [this message] 2021-01-26 19:38 ` [Bug c++/98835] " msebor at gcc dot gnu.org 2021-02-01 15:48 ` cvs-commit 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-98835-4@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).