From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D3F4F3858D28; Wed, 9 Feb 2022 17:24:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3F4F3858D28 From: "zhaoweiliew at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/25689] missed diagnostic about assignment used as truth value. Date: Wed, 09 Feb 2022 17:24:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: zhaoweiliew at gmail dot com 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: attachments.created 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 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: Wed, 09 Feb 2022 17:24:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D25689 --- Comment #3 from Zhao Wei Liew --- Created attachment 52395 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52395&action=3Dedit Test patch (seeking feedback) Hi! I wrote a small patch to fix this issue, but I think that it has much r= oom for improvement, though I'm not very sure how. Could anyone take a look and give me feedback on how I could improve the patch? Here's an example code snippet. I've commented the expected and actual diagnostic results beside the lines of code. struct A { A& operator=3D(int); operator bool(); }; void f(A a, A b) { if (a =3D 0); // GCC warns after patch (correct) if (a.operator=3D(0)) {} // GCC warns after patch (incorrect, but doesn't= sound like a major issue) if (a =3D b) {} // GCC does not warn before & after patch (incorrect) } Specifically, there are 2 issues: 1. GCC warns for `if (a.operator=3D(0))` 2. GCC does not warn for `if (a =3D b)` where the default copy/move assignm= ent operator is used. Thanks!=