C++: error: bitwise operation between different enumeration types (‘xxx‘ and ‘bbb’) is deprecated

https://bugzilla.redhat.com/show_bug.cgi?id=2211497
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1120r0.html

新的版本里c++20默认,不让做不同enum类型的比较,转换。这是一个避免错误的方法,应该建议使用。而且这种问题调试的时候,非常困难。
-Wdeprecated-enum-enum-conversion
-Wno-deprecated-enum-enum-conversion (C++ and Objective-C++ only)
Disable the warning about the case when the usual arithmetic conversions are applied on operands where one is of enumeration type and the other is of a different enumeration type. This conversion was deprecated in C++20. For example:
enum E1 { e };
enum E2 { f };
int k = f - e;
‘-Wdeprecated-enum-enum-conversion’ is enabled by default with ‘-std=c++20’. In pre-C++20 dialects, this warning can be enabled by ‘-Wenum-conversion’.

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/130980989