MISRA C++:2023 Rule 10.2.2
Description
Rule Definition
Unscoped enumerations should not be declared. 1
Rationale
Enumeration values in an unscoped enum can conflict with other identifiers in the same scope as the enum and cause compilation errors. For instance:
enum E: std::int32_t { E0, E1}; std::int32_t E0;
If you scope the enum, such conflicts can be avoided. For instance:
enum class E: std::int32_t { E0, E1}; std::int32_t E0;
Scoping the enum also disallows implicit conversions of the enumeration values to other types.
Polyspace Implementation
Polyspace® reports a violation on enumerations in your code that are not scoped. Unscoped enumerations within a class are not reported as violations of this rule.
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: Declarations |
Category: Advisory |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.