Just as comparing apples and oranges is seen as a classic folly, comparing values from different enumerations against each other or converting them
into one another is nonsensical. True, at root enum
s are simply named numbers, and it’s certainly valid to compare numbers. But an added
layer of meaning is created by an enum
, one that goes beyond simple numerical values.
Ignoring that extra layer of meaning is at best a trap for maintainers, who are likely to be hopelessly confused by the code. At worst, it is a
bug, which will lead to unexpected results.
Noncompliant code example
enum apple {BRAEBURN, FUJI, GRANNY_SMITH, RED_DELICIOUS};
enum orange {BLOOD, NAVEL, BITTER, BERGAMOT, MANDARIN};
void makeCider(apple v);
bool fun(apple v1, orange v2) {
makeCider((apple)v2); // Noncompliant
return v1 != v2; // Noncompliant
}