From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4564B395B413; Mon, 29 Aug 2022 23:48:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4564B395B413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661816900; bh=Eyn5LB8NaP1wSenOT1t0e333YubeWps+G8RRdRdo+3Q=; h=From:To:Subject:Date:From; b=bH2XUIBE1ykXE0/Hdek2SHhgEJl1F7SqEXZPkYVRSUOjmvFd0mZCfAQC41Yb7t8Mg jGH/vpnfg68bKWwqnN9c2dqfhNUs5i+DoGkuNulL8nGeCE8paEsu0/RxAvmA5dfhSe FZpjqxtFDQx+v96KaX69/HN+UR1tzGk7qnlfhoCc= From: "f.heckenbach@fh-soft.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106774] New: warning about comparison to true/false Date: Mon, 29 Aug 2022 23:48:19 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: f.heckenbach@fh-soft.de 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=3D106774 Bug ID: 106774 Summary: warning about comparison to true/false Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: f.heckenbach@fh-soft.de Target Milestone: --- gcc has "-Wbool-compare" to warn about boolean expression compared with an integer value different from true/false. This warning is enabled by -Wall. However, a warning for comparisons with true and false may also be useful. = The former is redundant, the latter can be replaced with "!". Actually, this warning may also be given when comparing a non-Boolean integ= ral expression with true or false. The former is not redundant, but may often n= ot be what's intended (if so, one should compare with 1). The latter is equiva= lent to comparing with 0, but still strange style. And comparing non-integral (e= .g. floating-point) expressions with Boolean literals is certainly warning-wort= hy (though it may be caught by "-Wfloat-equal" as well). To sum up, a new warning about comparing any expression with true/false literals.=20 Maybe something like "-Wbool-compare=3D2" (which would not be enabled by -W= all, I guess; maybe by -Wextra, but even if it must be given manually, I'd find it useful).=