Rule Definition
Enumerations have implementation-defined representation and so should not be used in arithmetic contexts.
Remediation
Use Enum types with: the subscript operator [ ], the assignment operator =, the equality operators == and !=, the unary & operator, and the relational operators <, <=, >, >=
Violation Code Sample
enum { COLOUR_0, COLOUR_1, COLOUR_2, COLOUR_COUNT } colour;
if ( ( COLOUR_0 + COLOUR_1 ) == colour ) // Non-compliant
Fixed Code Sample
enum { COLOUR_0, COLOUR_1, COLOUR_2, COLOUR_COUNT } colour;
if ( COLOUR_0 == colour ) // Compliant
if ( colour < COLOUR_COUNT ) // Compliant
Reference
MISRA CPP 2008, 4-5-2: Expressions with type enum shall not be used as operands to built-in operators other than the subscript operator [ ], the assignment operator =, the equality operators == and !=, the unary & operator, and the relational operators <, <=, >, >=.
Related Technologies
Technical Criterion
Complexity - Algorithmic and Control Structure Complexity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.