From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 631D63858C56; Wed, 31 Aug 2022 10:33:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 631D63858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661942025; bh=WgG+6Ix5Vv+NsPetaEw1L6/p/uqU/0JAQIKgFdeJGEY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UdeFhzJeKZEHGZLd5Yl+MIDgGdrbWXRu5NAKm3PCuki5Sa04X17f6XG8NO6mT52/n Ei7atPz6E7auMJ0+IAztFmyZSRyBjjhh1i1+UOI9CaoLNbTbLoXTKB/iXSihztdV0u RaPHJDdjewAMoXVAtrD1N4Jp4o/hkxaSJxnqiQqg= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106774] warning about comparison to true/false Date: Wed, 31 Aug 2022 10:33:44 +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: unknown X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org 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_severity blocked 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=3D106774 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Blocks| |87403 --- Comment #5 from Jonathan Wakely --- (In reply to Frank Heckenbach from comment #2) > This should cover all cases mentioned: >=20 > void t (bool a, int i, float e, double f) > { > // Boolean literal comparisons > if (a =3D=3D true) // better: if (a) > return; > if (a =3D=3D false) // better: if (!a) > return; > if (a !=3D true) // better: if (!a) > return; > if (a !=3D false) // better: if (a) > return; > // also reversed to be sure > if (true =3D=3D a) // better: if (a) > return; > if (false !=3D a) // better: if (a) > return; These are definitely coding style, and I don't think a warning is warranted. >=20 > // Integer comparisons to Boolean literals > if (i =3D=3D true) // better: if (i =3D=3D 1) Or maybe it was meant to be ((bool)i =3D true). Warning for these does seem more useful IMO. The arithmetic promotions from bool to int (or float) mean the comparison doesn't do what it appears to do, and there seems no reason to use a true/false literal there. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D87403 [Bug 87403] [Meta-bug] Issues that suggest a new warning=