AUTOSAR C++14 Rule A7-2-4
In an enumeration, either (1) none, (2) the first or (3) all enumerators shall be initialized
Description
Rule Definition
In an enumeration, either (1) none, (2) the first or (3) all enumerators shall be initialized.
Rationale
In an enumeration, you can explicitly assign values to one or more enumerators and leave the compiler to deduce the remaining values. However, mixing explicit and implicit assignments can cause confusion for developers or code reviewers.
Polyspace Implementation
The rule checker reports violations on enum definitions if some of the enumerators are assigned explicit values, except the following cases:
The first enumerator is assigned an explicit value.
All enumerators are assigned an explicit value.
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: Declaration |
Category: Required, Automated |
Version History
Introduced in R2019a