AUTOSAR C++14 Rule A7-2-2
Enumeration underlying type shall be explicitly defined
Description
Rule Definition
Enumeration underlying type shall be explicitly defined.
Rationale
In an unscoped enumeration declaration such as:
enum someEnum : type { ... }
if :
is omitted, the underlying type
is implementation-defined (with the only requirement that the type must accommodate all the
enumeration values). Not declaring an underlying type explicitly results in
implementation-defined behavior.type
In a scoped enumeration declaration such as:
enum class someEnum : type { ... }
if :
is omitted, the underlying type
is type
int
. If an enumeration value exceeds the values allowed for
int
, you see compilation errors.
For both unscoped and scoped enumerations, declare the underlying type explicitly to avoid implementation-defined behavior or compilation errors.
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 R2019b