Main Content
AUTOSAR C++14 Rule A6-4-1
A switch
statement shall have at least two case-clauses, distinct
from the default label
Description
Rule Definition
A switch
statement shall have at least two case-clauses, distinct
from the default label.
Rationale
A switch
statement with no case-clauses is redundant. Use an
if
statement to better express a switch
statement
with a single case-clause.
Polyspace Implementation
This rule checker reports a violation for switch
statements that
contain less than two case-clauses in addition to the default-clause. This includes
situations where no case-clause
exists.
switch (x) { //Noncompliant default: //... 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