Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.4 KB

c26828.md

File metadata and controls

63 lines (49 loc) · 1.4 KB
title description ms.date f1_keywords helpviewer_keywords
Warning C26828
Learn more about: Warning C26828
05/17/2023
C26828
MIXING_OVERLAPPING_ENUMS
C26828

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