Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.56 KB

File metadata and controls

42 lines (33 loc) · 1.56 KB
title description ms.date f1_keywords helpviewer_keywords
Compiler Warning C5054
Compiler warning C5054 description and solution.
02/22/2022
C5054
C5054

Compiler warning (level 4) C5054

operator 'operator-name': deprecated between enumerations of different types

Remarks

C++20 has deprecated the usual arithmetic conversions on operands, where one operand is of enumeration type and the other is of a different enumeration type. For more information, see C++ Standard proposal P1120R0.

In Visual Studio 2019 version 16.2 and later, an implicit conversion between enumeration types produces a level 4 warning when the /std:c++latest compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under /std:c++20.

Example

In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 warning when the /std:c++latest compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under /std:c++20:

// C5054.cpp
// Compile using: cl /EHsc /W4 /std:c++latest C5054.cpp
enum E1 { a };
enum E2 { b };
int main() {
    int i = a | b; // warning C5054: operator '|': deprecated between enumerations of different types
}

To avoid the warning, use static_cast to convert the second operand:

// C5054_fixed.cpp
// Compile using: cl /EHsc /W4 /std:c++latest C5054_fixed.cpp
enum E1 { a };
enum E2 { b };
int main() {
  int i = a | static_cast<int>(b);
}