From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2A6B53857B99; Tue, 11 Oct 2022 08:16:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A6B53857B99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665476166; bh=GNANVV5+rs4eiCmXEH2S7jiyqdB/2dcYTRIjTjfJQn8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gHXVAV4Rn2uhIKlAa96ICvme1aVkuM1p8VaTI/B9yBlMrcoR3O6TvCpGqF6swRB1U 2PUXFD8V8QfcWIcyNmV1ig4qPYs8/5z/9Ks19qm9XCYw0l6Py8THOdhc3eDmAAQ0FD wWMTi0IchdGQO5GsQ9E9oyig+vpgeS2UTjp3Lk8Y= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107206] Bogus -Wuninitialized in std::optional Date: Tue, 11 Oct 2022 08:16:05 +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: 12.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: component bug_status cf_reconfirmed_on everconfirmed 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=3D107206 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c++ |libstdc++ Status|UNCONFIRMED |NEW Last reconfirmed| |2022-10-11 Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- Confirmed. We diagnose [local count: 1073741824]: MEM[(struct optional *)&y + 4B] =3D{v} {CLOBBER}; MEM[(union _Storage *)&y + 4B] =3D{v} {CLOBBER}; MEM[(struct _Optional_payload_base *)&y + 4B]._M_engaged =3D 0; D.11546.o =3D y.o; SR.27_14 =3D MEM [(struct optional *)&y + 4B]; <--------- this MEM [(struct optional *)&D.11546 + 4B] =3D SR.27_14; MEM [(struct optional *)&D.11546 + 8B] =3D 0; MEM[(struct Y *)&z].o =3D MEM[(const struct Y &)&D.11546].o; D.11546 =3D{v} {CLOBBER(eol)}; MEM[(struct Y *)&w] =3D{v} {CLOBBER}; MEM[(struct X *)&w] =3D{v} {CLOBBER}; MEM[(struct X *)&w].i =3D 0; MEM [(struct optional *)&z + 4B] =3D 1; MEM [(struct optional *)&z + 8B] =3D 1; MEM[(struct Y *)&w].o =3D MEM[(const struct Y &)&z].o; f (&w.y); y =3D{v} {CLOBBER(eol)}; z =3D{v} {CLOBBER(eol)}; w =3D{v} {CLOBBER(eol)}; return; Here the aggregate copy D.11546.o =3D y.o; is effectively scalarized and that accesses the data member of the not engaged std::optional<>. IMHO that's a standard library issue? The copy is due to the by value passing and we get in .original <>> (const struct Y &) &y >>>>) >>>>>; which eventually leads to Y::Y (&D.11546, &y); Z::Z (&z, &D.11546); which contains void Y::Y (struct Y * const this, const struct Y & D.11498) { *this =3D {CLOBBER}; { _1 =3D &this->x; _2 =3D &D.11498->x; X::X (_1, _2); this->o =3D D.11498->o; } so the std::optional<> is simply aggregate copied, accessing any not engaged member. GCC is correct in diagnosing this uninitialized access.=