From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C82E23857C52; Thu, 24 Sep 2020 15:43:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C82E23857C52 From: "davidfink314 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97197] New: With -O2, Incorrect -Werror=maybe-uninitialized thrown, leads to 'target_mem_ref' and 'dump_expr' in message Date: Thu, 24 Sep 2020 15:43:09 +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: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: davidfink314 at gmail 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: Thu, 24 Sep 2020 15:43:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97197 Bug ID: 97197 Summary: With -O2, Incorrect -Werror=3Dmaybe-uninitialized thrown, leads to 'target_mem_ref' and 'dump_expr' in message Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: davidfink314 at gmail dot com Target Milestone: --- Bug looks like it was introduced in gcc 7 reproduces in gcc trunk Output: x86-64 gcc (trunk) -O2 -Werror=3Dmaybe-uninitialized 1 x86-64 gcc (trunk) - cached In copy constructor 'Normal::Normal(const Normal&)', inlined from 'Combo::Combo(const Combo&)' at :21:8, inlined from 'void Y::f()' at :36:24: :18:35: error: ''target_mem_ref' not supported by dump_expr' may be used uninitialized [-Werror=3Dmaybe-uninitialized] 18 | Normal(Normal const& o) : p(o.p /* warning here for no good rea= son */) { } | ~~^ : In member function 'void Y::f()': :36:16: note: 'combo' declared here 36 | for (Combo combo : comboList) { /* implicit copy required to reproduce bug */ | ^~~~~ cc1plus: some warnings being treated as errors Compiler returned: 1 Input: https://godbolt.org/z/b73cY8 -O2 -Werror=3Dmaybe-uninitialized #include struct Weirdo { // nonstandard copy constructor bool data{false}; // initializer here required to reproduce bug Weirdo() =3D default; Weirdo(const Weirdo& o) { // data should still be set to false via {} above and not being lis= ted // original code had this in the assignment operator, and the copy constructor called the assignment operator. if (this !=3D &o) { // pointer check required to reproduce bug data =3D o.data; } } }; struct Normal { bool p{false}; Normal() =3D default; Normal(Normal const& o) : p(o.p /* warning here for no good reason */) = { } }; struct Combo { Combo() : v(), q() {} void g(); Weirdo v; Normal q; }; struct Y { void f(); std::vector comboList; }; void Y::f() { for (Combo combo : comboList) { /* implicit copy required to reproduce = bug */ combo.v.data && (combo.g(), false); } }=