Edit

Share via


Warning C26828

Different enum types have overlapping values. Did you want to use another enum constant here?

Remarks

Most of the time, a single enumeration type describes all the bit flags that you can use for an option. If you use two different enumeration types that have overlapping values in the same bitwise expression, the chances are good those enumeration types weren't designed for use together.

Code analysis name: MIXING_OVERLAPPING_ENUMS

Example

The following sample code causes warning C26828:

enum BitWiseA
{
    A = 1,
    B = 2,
    C = 4
};

enum class BitWiseB
{
    AA = 1,
    BB = 2,
    CC = 4,
    All = 7
};

int overlappingBitwiseEnums(BitWiseA a) 
{
    return (int)a|(int)BitWiseB::AA; // Warning C26828: Different enum types have overlapping values. Did you want to use another enum constant here?
}

To fix the warning, make sure enumeration types designed for use together have no overlapping values. Or, make sure all the related options are in a single enumeration type.

enum BitWiseA
{
    A = 1,
    B = 2,
    C = 4
};

int overlappingBitwiseEnums(BitWiseA a) 
{
    return (int)a|(int)BitWiseA::A; // No warning.
}

See also

C26813
C26827