MISRAC++2008-5-0-14
In this section:
Synopsis
(Required) The first operand of a conditional-operator shall have type bool.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Non-boolean operands to the conditional ( ? : ) operator were found. This check is identical to MISRAC2004-13.2_e.
Coding standards
- MISRA C:2004 13.2
(Advisory) Tests of a value against zero should be made explicit, unless the operand is effectively boolean.
Code examples
The following code example fails the check and will give a warning:
void example(int x) {
int z;
z = x ? 1 : 2; //x is an int, not a bool
}
The following code example passes the check and will not give a warning about this issue:
void example(bool b) {
int x;
x = b ? 1 : 2; //OK - b is a bool
}