MISRAC2012-Rule-16.7
In this section:
Synopsis
(Required) A switch-expression shall not have essentially Boolean type
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A switch expression was found that represents a value that is effectively Boolean. This check is identical to MISRAC2004-15.4, MISRAC++2008-6-4-7.
Coding standards
- MISRA C:2004 15.4
(Required) A switch expression shall not represent a value that is effectively boolean.
- MISRA C:2012 Rule-16.7
(Required) A switch-expression shall not have essentially Boolean type
- MISRA C++ 2008 6-4-7
(Required) The condition of a switch statement shall not have bool type.
Code examples
The following code example fails the check and will give a warning:
void example(int x) {
switch(x == 0) {
case 0:
case 1:
default:
}
}
The following code example passes the check and will not give a warning about this issue:
void example(int x) {
switch(x) {
case 1:
case 0:
default:
}
}