Unnecessary large enum base type
Description
This defect occurs when the base type of an enum object is larger
than necessary. For example, consider the enumeration
myEnum:
enum class myEnum : uint64_t { ZERO, ONE, TWO, THREE = UINT16_MAX };enum object has the value
UINT16_MAX. That is, a base type of uint16_t is
sufficient to hold the enumerators. But the base type is specified as
uint64_t, which is unnecessarily large. Polyspace® reports a defect.Risk
Using unnecessarily large base type for enumerations results in using more memory than necessary during program execution.
Fix
To fix this defect, use an enumeration base type that is no larger than necessary to hold the largest enumerator. For example:
enum class myEnum : uint16_t { ZERO, ONE, TWO, THREE = UINT16_MAX };Performance improvements might vary based on the compiler, library implementation, and environment that you are using.
Examples
Result Information
| Group: Performance |
| Language: C++ |
| Default: Off |
Command-Line Syntax:
ENUM_BASE_TYPE_TOO_LARGE
|
| Impact: Medium |
PQL Name:
std.defects.ENUM_BASE_TYPE_TOO_LARGE
|
Version History
Introduced in R2026a
See Also
Find defects
(-checkers) | Expensive local
variable copy | Reference to un-named
temporary
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)
- Expensive-to-Read Objects in Bug Finder