MISRAC++2008-6-4-6
In this section:
Synopsis
(Required) The final clause of a switch statement shall be the default-clause.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Switch statements without a default clause, or with a default clause that is not the final clause, were found. This check is identical to MISRAC2004-15.3.
Coding standards
- CWE 478
Missing Default Case in Switch Statement
- MISRA C:2004 15.3
(Required) The final clause of a switch statement shall be the default clause.
Code examples
The following code example fails the check and will give a warning:
int example(int x) {
switch(x){
default:
return 2;
break;
case 0:
return 0;
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;
}
}