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;
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.
Equivalent to negative && !other_negative.
(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.
There is nothing abstractly wrong with ordering false and true.
This is just a style issue really ...