My current code resembles this:
enum Enum1 : signed __int8
{
Value1 = 1 ,
Value2 = 2 ,
Value3 = -3 // C4341
} ;
The error details state:
"warning C4341: 'Value3' : signed value is out of range for enum constant"
MSDN states that this warning only occurs when you use values outside of the range of an int:
(> 2^31) OR (< 1 - 2^31)
Why is it telling me that my negative values are invalid? It is only a warning, but Google is telling me that this warning indicates that these enum values will be undefined - which will break my program.
Seems like a bug to me. The current 0x draft doesn't indicate that this should be the case, and neither does the MSDN documentation.
Your answer is basically described here: Are C++ enums signed or unsigned?
It is up to your compiler's implementation to define whether the value of the enum is signed or unsigned. I assume they left the warning there so that if you or someone else uses a different compiler, you may get different behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With