MISRAC2004-12.6_a
In this section:
Synopsis
(Advisory) The operands of logical operators (&&, ||, and !) should be effectively boolean.
Enabled by default
No
Severity/Certainty
Low/Medium

Full description
Operands of logical operators (&&, ||, and !) were found that are not effectively Boolean. This check is identical to MISRAC++2008-5-3-1.
Coding standards
- MISRA C:2004 12.6
(Advisory) The operands of logical operators (&&, ||, and !) should be effectively boolean. Expressions that are effectively boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, and ?:).
- MISRA C++ 2008 5-3-1
(Required) Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int d, c, b, a;
d = ( c & a ) && b;
}
The following code example passes the check and will not give a warning about this issue:
typedef char boolean_t; /* Compliant: Boolean-by-enforcement */
void example(void)
{
boolean_t d;
boolean_t c = 1;
boolean_t b = 0;
boolean_t a = 1;
d = ( c && a ) && b;
}