public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "f.heckenbach@fh-soft.de" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-106774-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106774

            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 integral
expression with true or false. The former is not redundant, but may often not
be what's intended (if so, one should compare with 1). The latter is equivalent
to comparing with 0, but still strange style. And comparing non-integral (e.g.
floating-point) expressions with Boolean literals is certainly warning-worthy
(though it may be caught by "-Wfloat-equal" as well).

To sum up, a new warning about comparing any expression with true/false
literals. 

Maybe something like "-Wbool-compare=2" (which would not be enabled by -Wall, I
guess; maybe by -Wextra, but even if it must be given manually, I'd find it
useful).

             reply	other threads:[~2022-08-29 23:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29 23:48 f.heckenbach@fh-soft.de [this message]
2022-08-29 23:52 ` [Bug c++/106774] " pinskia at gcc dot gnu.org
2022-08-30  0:02 ` f.heckenbach@fh-soft.de
2022-08-30  7:09 ` rguenth at gcc dot gnu.org
2022-08-30 23:50 ` egallager at gcc dot gnu.org
2022-08-31 10:33 ` redi at gcc dot gnu.org
2022-08-31 23:46 ` f.heckenbach@fh-soft.de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106774-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).