Main Content
AUTOSAR C++14 Rule M6-4-7
The condition of a switch statement shall not have bool type
Description
Rule Definition
The condition of a switch statement shall not have bool type.
Rationale
Switch statements that have a bool condition might cause confusion or mistakes not caught by the compiler. If statements are better suited to handling bool evaluations. Use If...else statements in place of switch statements that have a bool condition.
Polyspace Implementation
Polyspace® raises this defect whenever a switch-case conditional results in a bool.
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