根据Bathsheba的要求并作为对“如果枚举类型无法适应整数类型会发生什么?”问题的跟进:
假设枚举定义如下:
enum foo : unsigned int
{
bar = UINT_MAX,
oops
};
oops
的值是否已定义?
MSVS2015编译:
warning C4340: 'oops': value wrapped from positive to negative value
warning C4309: 'initializing': truncation of constant value
warning C4369: 'oops': enumerator value '4294967296' cannot be represented as 'unsigned int', value is '0'
MSVS2015输出:
bar = 4294967295
oops= 0
gcc 4.9.2编译:
9 : note: in expansion of macro 'UINT_MAX'
bar = UINT_MAX,
^
10 : error: enumerator value 4294967296l is outside the range of underlying type 'unsigned int'
oops
^
Compilation failed
gcc 4.9.2 的输出
//compilation failed