public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-106774-4-PmvUbrUjUi@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-106774-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106774 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Blocks| |87403 --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Frank Heckenbach from comment #2) > This should cover all cases mentioned: > > void t (bool a, int i, float e, double f) > { > // Boolean literal comparisons > if (a == true) // better: if (a) > return; > if (a == false) // better: if (!a) > return; > if (a != true) // better: if (!a) > return; > if (a != false) // better: if (a) > return; > // also reversed to be sure > if (true == a) // better: if (a) > return; > if (false != a) // better: if (a) > return; These are definitely coding style, and I don't think a warning is warranted. > > // Integer comparisons to Boolean literals > if (i == true) // better: if (i == 1) Or maybe it was meant to be ((bool)i = 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=87403 [Bug 87403] [Meta-bug] Issues that suggest a new warning
next prev parent reply other threads:[~2022-08-31 10:33 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-29 23:48 [Bug c++/106774] New: " f.heckenbach@fh-soft.de 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 [this message] 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-PmvUbrUjUi@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: linkBe 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).