ENUM-bounds
In this section:
Synopsis
Conversions to enum that are out of range of the enumeration.
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
There are conversions to enum that are out of range of the enumeration. This check is identical to MISRAC++2008-7-2-1.
Coding standards
- MISRA C++ 2008 7-2-1
(Required) An expression with enum underlying type shall only have values corresponding to the enumerators of the enumeration.
Code examples
The following code example fails the check and will give a warning:
enum ens { ONE, TWO, THREE };
void example(void)
{
ens one = (ens)10;
}
The following code example passes the check and will not give a warning about this issue:
enum ens { ONE, TWO, THREE };
void example(void)
{
ens one = ONE;
ens two = TWO;
two = one;
}