AUTOSAR C++14 Rule M6-4-5
An unconditional throw or break statement shall terminate every non-empty switch-clause
Description
Rule Definition
An unconditional throw or break statement shall terminate every non-empty switch-clause.
Rationale
If a throw or break statement is not used at the end of a switch-clause, control flow falls into the next switch-clause. If unintentional, this behavior might cause unexpected results. Using a throw or break statement helps to prevent unintentional fall-through behavior. Use a throw or break statement as the last statement of each case-clause and the default-clause.
Using an empty case-label is acceptable when utilizing fall-through to group together multiple clauses that otherwise require identical statements.
Polyspace Implementation
Polyspace® raises this defect whenever a case-label contains any statements and a throw or break statement is not the final statement of the case-label.
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