public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105581] New: boolean types and relational operators problem
@ 2022-05-12 10:11 dcb314 at hotmail dot com
2022-05-12 10:23 ` [Bug c/105581] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-05-12 10:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
Bug ID: 105581
Summary: boolean types and relational operators problem
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: ---
For this C code:
void g( int );
void f( bool a, bool b)
{
if (a < b)
g( 1);
}
recent gcc doesn't find a problem:
$ /home/dcb/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra -pedantic may12a.cc
$
Here is cppcheck complaining:
$ /home/dcb/cppcheck/trunk.git/cppcheck --enable=all may12a.cc
may12a.cc:6:8: style: Comparison of a variable having boolean value using
relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]
if (a < b)
^
$
There is an example in the gcc source code:
trunk.git/gcc/sreal.h:72:25: style: Comparison of a variable having boolean
value using relational (<, >, <= or >=) operator.
[comparisonOfBoolWithBoolError]
Source code is
return negative > other_negative;
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] boolean types and relational operators problem
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
@ 2022-05-12 10:23 ` pinskia at gcc dot gnu.org
2022-05-12 10:46 ` schwab@linux-m68k.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-12 10:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Well. There is a meaning for the code though.
That is negative > other_negative
Means negative is true while other_negative is false the result will be true
which is exactly what it is testing here.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] boolean types and relational operators problem
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
2022-05-12 10:23 ` [Bug c/105581] " pinskia at gcc dot gnu.org
@ 2022-05-12 10:46 ` schwab@linux-m68k.org
2022-05-12 11:49 ` dcb314 at hotmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: schwab@linux-m68k.org @ 2022-05-12 10:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
Equivalent to negative && !other_negative.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] boolean types and relational operators problem
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
2022-05-12 10:23 ` [Bug c/105581] " pinskia at gcc dot gnu.org
2022-05-12 10:46 ` schwab@linux-m68k.org
@ 2022-05-12 11:49 ` dcb314 at hotmail dot com
2022-05-12 12:12 ` schwab@linux-m68k.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-05-12 11:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
--- Comment #3 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Well. There is a meaning for the code though.
> That is negative > other_negative
> Means negative is true while other_negative is false the result will be true
> which is exactly what it is testing here.
In abstract, false and true can't be compared with "<".
In the implementation choice of false as 0 and true as 1, then relying
on the implementation values does make "<" valid.
I think that's the bad style cppcheck is complaining about. It's just
better style to have it as a logical expression, as Andreas shows.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] boolean types and relational operators problem
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
` (2 preceding siblings ...)
2022-05-12 11:49 ` dcb314 at hotmail dot com
@ 2022-05-12 12:12 ` schwab@linux-m68k.org
2022-10-27 6:45 ` [Bug c/105581] new warning about boolean types and relational operators pinskia at gcc dot gnu.org
2022-10-27 6:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: schwab@linux-m68k.org @ 2022-05-12 12:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
--- Comment #4 from Andreas Schwab <schwab@linux-m68k.org> ---
There is nothing abstractly wrong with ordering false and true.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] new warning about boolean types and relational operators
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
` (3 preceding siblings ...)
2022-05-12 12:12 ` schwab@linux-m68k.org
@ 2022-10-27 6:45 ` pinskia at gcc dot gnu.org
2022-10-27 6:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-27 6:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |87403
Summary|boolean types and |new warning about boolean
|relational operators |types and relational
|problem |operators
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is just a style issue really ...
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/105581] new warning about boolean types and relational operators
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
` (4 preceding siblings ...)
2022-10-27 6:45 ` [Bug c/105581] new warning about boolean types and relational operators pinskia at gcc dot gnu.org
@ 2022-10-27 6:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-27 6:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105581
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-10-27 6:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 10:11 [Bug c/105581] New: boolean types and relational operators problem dcb314 at hotmail dot com
2022-05-12 10:23 ` [Bug c/105581] " pinskia at gcc dot gnu.org
2022-05-12 10:46 ` schwab@linux-m68k.org
2022-05-12 11:49 ` dcb314 at hotmail dot com
2022-05-12 12:12 ` schwab@linux-m68k.org
2022-10-27 6:45 ` [Bug c/105581] new warning about boolean types and relational operators pinskia at gcc dot gnu.org
2022-10-27 6:45 ` pinskia at gcc dot gnu.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).