public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/106455] New: bad style: comparatives over booleans ? @ 2022-07-27 14:11 dcb314 at hotmail dot com 2022-07-27 14:45 ` [Bug c/106455] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: dcb314 at hotmail dot com @ 2022-07-27 14:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106455 Bug ID: 106455 Summary: bad style: comparatives over booleans ? Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dcb314 at hotmail dot com Target Milestone: --- Static analyser cppcheck says for recent gcc trunk: trunk.git/gcc/sreal.h:72:25: style: Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError] Source code is bool negative = m_sig < 0; bool other_negative = other.m_sig < 0; if (negative != other_negative) return negative > other_negative; I agree - this looks bad style to me. I don't think > should work on booleans. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/106455] bad style: comparatives over booleans ? 2022-07-27 14:11 [Bug c/106455] New: bad style: comparatives over booleans ? dcb314 at hotmail dot com @ 2022-07-27 14:45 ` pinskia at gcc dot gnu.org 2022-07-27 15:07 ` schwab@linux-m68k.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2022-07-27 14:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106455 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |WONTFIX Status|UNCONFIRMED |RESOLVED --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is not bad style at all. bool > bool works just fine and is exactly what we want to test here. Basically it means negative && !other_negative ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/106455] bad style: comparatives over booleans ? 2022-07-27 14:11 [Bug c/106455] New: bad style: comparatives over booleans ? dcb314 at hotmail dot com 2022-07-27 14:45 ` [Bug c/106455] " pinskia at gcc dot gnu.org @ 2022-07-27 15:07 ` schwab@linux-m68k.org 2022-07-27 15:15 ` dcb314 at hotmail dot com 2022-07-27 15:18 ` schwab@linux-m68k.org 3 siblings, 0 replies; 5+ messages in thread From: schwab@linux-m68k.org @ 2022-07-27 15:07 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106455 --- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> --- negative && !other_negative is definitely easier to understand than negative > other_negative. In fact, given the condition negative != other_negative, negative already implies !other_negative, so this can be simplified to just if (negative != other_negative) return negative. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/106455] bad style: comparatives over booleans ? 2022-07-27 14:11 [Bug c/106455] New: bad style: comparatives over booleans ? dcb314 at hotmail dot com 2022-07-27 14:45 ` [Bug c/106455] " pinskia at gcc dot gnu.org 2022-07-27 15:07 ` schwab@linux-m68k.org @ 2022-07-27 15:15 ` dcb314 at hotmail dot com 2022-07-27 15:18 ` schwab@linux-m68k.org 3 siblings, 0 replies; 5+ messages in thread From: dcb314 at hotmail dot com @ 2022-07-27 15:15 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106455 --- Comment #3 from David Binderman <dcb314 at hotmail dot com> --- (In reply to Andrew Pinski from comment #1) > bool > bool works just fine and is exactly what we want to test here. Confused. So is false > true or true > false ? ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/106455] bad style: comparatives over booleans ? 2022-07-27 14:11 [Bug c/106455] New: bad style: comparatives over booleans ? dcb314 at hotmail dot com ` (2 preceding siblings ...) 2022-07-27 15:15 ` dcb314 at hotmail dot com @ 2022-07-27 15:18 ` schwab@linux-m68k.org 3 siblings, 0 replies; 5+ messages in thread From: schwab@linux-m68k.org @ 2022-07-27 15:18 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106455 --- Comment #4 from Andreas Schwab <schwab@linux-m68k.org> --- bool > bool is evaluated as (int)bool > (int)bool. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-27 15:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-07-27 14:11 [Bug c/106455] New: bad style: comparatives over booleans ? dcb314 at hotmail dot com 2022-07-27 14:45 ` [Bug c/106455] " pinskia at gcc dot gnu.org 2022-07-27 15:07 ` schwab@linux-m68k.org 2022-07-27 15:15 ` dcb314 at hotmail dot com 2022-07-27 15:18 ` schwab@linux-m68k.org
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).