Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.4 KB

File metadata and controls

63 lines (49 loc) · 1.4 KB
title Warning C26828
description Learn more about: Warning C26828
ms.date 05/17/2023
f1_keywords
C26828
MIXING_OVERLAPPING_ENUMS
helpviewer_keywords
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