AUTOSAR C++14 Rule M6-4-6
The final clause of a switch
statement shall be the
default-clause
Description
Rule Definition
The final clause of a switch
statement shall be the
default-clause.
Rationale
It is a good defensive programming technique to always use a default
clause as the final clause of a switch
statement. The default
clause must either take appropriate action or contain a comment as to why the default
clause takes no action.
Polyspace Implementation
The rule checker detects switch
statements that do not have a final
default
clause.
The rule checker does not report a violation if the switch
variable
is an enumeration with finite number of values and you have a case
clause
for each value. For
instance:
enum Colors { RED, BLUE, YELLOW } color; switch (color) { case RED: break; case BLUE: break; case YELLOW: break; }
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Statements |
Category: Required, Automated |
Version History
Introduced in R2019a