From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CCD703858D37; Mon, 21 Aug 2023 19:26:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCD703858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692645980; bh=/dgrEjXVk5FWPnFTegGkbU56AGFv6NjgcVEcXjp6A5M=; h=From:To:Subject:Date:From; b=vpVuAwBhjdR+B+FTZpFUvNai8G6mKKFs0buQksiuPpsByzkRGcu6dgzq5HCVuKVrg SmsS8uZbKsw1GHKUmTBUf6JSp79BJWPdZRqVLQwYlrmNS6H1IftLfMU7Sm9kpGsbB/ W7lLT1zwx64KprtODFKqGOOAspCPIBotY+y+eb2U= From: "ed at catmur dot uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111094] New: Spurious Wuninitialized swapping underlying bytes of object representation in move constructor Date: Mon, 21 Aug 2023 19:26:20 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ed at catmur dot uk 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111094 Bug ID: 111094 Summary: Spurious Wuninitialized swapping underlying bytes of object representation in move constructor Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- struct S { short x, y; }; struct A { A() {} A(A&& rhs) { auto p =3D reinterpret_cast(&s); auto q =3D reinterpret_cast(&rhs.s); for (int i =3D 0; i !=3D sizeof s; ++i) { auto t =3D p[i]; p[i] =3D q[i]; q[i] =3D t; } } bool b =3D false; S s; }; A f() { A a; A b =3D static_cast(a); return b; } at -O3 -Wall: In constructor 'A::A(A&&)', inlined from 'A f()' at :18:29: :9:23: warning: '*(__vector(4) unsigned char*)((char*)&a + offsetof= (A, A::s.S::x))' is used uninitialized [-Wuninitialized] 9 | p[i] =3D q[i]; | ~~~^ : In function 'A f()': :17:7: note: 'a' declared here 17 | A a; | ^ I'm reasonably sure that this usage of swapping underlying bytes is OK by [basic.indet]/2.3. (Motivation is e.g. optional with empty-on-move behavior and optimization f= or trivial types.)=