From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AFA743AA991D; Tue, 26 Jan 2021 09:33:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFA743AA991D From: "jchl at arista dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jchl at arista dot com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2021 09:33:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98835 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 #include class Good { public: Good & operator=3D(Good const &) =3D default; }; class Bad { public: Bad & operator=3D(Bad const &) & =3D default; }; template void test() { static_assert(std::is_trivially_copyable_v); T value1; T value2; std::memcpy(&value1, &value2, sizeof(T)); } int main() { test(); test(); } [See: https://godbolt.org/z/4vj9GT ] GCC trunk on x86_64 incorrectly gives the following warning: : In instantiation of 'void test() [with T =3D Bad]': :24:15: required from here :19:16: warning: 'void* memcpy(void*, const void*, size_t)' writi= ng 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.=