Warning C26827
Did you forget to initialize an enum, or intend to use another type?
Remarks
Most enum
types used in bitwise operations are expected to have members with values of powers of two. This warning attempts to find cases where a value wasn't given explicitly to an enumeration constant. It also finds cases where the wrong enumeration type may have been used inadvertently.
Code analysis name: ALMOST_BITWISE_ENUM
Example
The following sample code causes warning C26827:
enum class AlmostBitWise
{
A = 1,
B = 2,
C = 4,
D
};
int almostBitwiseEnums(AlmostBitWise a, bool cond)
{
return (int)a|(int)AlmostBitWise::A; // Warning C26827: Did you forget to initialize an enum, or intend to use another type?
}
To fix the warning, initialize the enumeration constant to the correct value, or use the correct enumeration type in the operation.
enum class AlmostBitWise
{
A = 1,
B = 2,
C = 4,
D = 8
};
int almostBitwiseEnums(AlmostBitWise a, bool cond)
{
return (int)a|(int)AlmostBitWise::A; // No warning.
}
See also
Feedback
https://aka.ms/ContentUserFeedback.
Binnenkort beschikbaar: In de loop van 2024 zullen we GitHub-problemen geleidelijk uitfaseren als het feedbackmechanisme voor inhoud en deze vervangen door een nieuw feedbacksysteem. Zie voor meer informatie:Feedback verzenden en weergeven voor