MISRAC2004-15.5
In this section:
Synopsis
(Required) Every switch statement shall have at least one case clause.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Switch statements without case clauses were found. This check is identical to MISRAC++2008-6-4-8, MISRAC++2023-9.4.2_d.
Coding standards
- MISRA C:2004 15.5
(Required) Every switch statement shall have at least one case clause.
- MISRA C++ 2008 6-4-8
(Required) Every switch statement shall have at least one case-clause.
- MISRA C++ 2023 9.4.2
(Required) The structure of a switch statement shall be appropriate
Code examples
The following code example fails the check and will give a warning:
int example(int x) {
switch(x){
default:
return 2;
break;
}
}
The following code example passes the check and will not give a warning about this issue:
int example(int x) {
switch(x){
case 3:
return 0;
break;
case 5:
return 1;
break;
default:
return 2;
break;
}
}