What is the type of enumeration constant, when it is used outside unscoped enum definition?
Consider following code:
#include <iostream>
enum modes
{
begin = 0,
end = 1
};
int main()
{
std::cout << std::boolalpha
<< std::is_same<unsigned int, typename std::underlying_type<modes>::type>::value
<< std::endl;
std::cout << sizeof(modes) << std::endl;
std::cout << (-100 + end) << std::endl;
}
This yields on my machine:
true
4
-99
Now, if I only change the value of some other enumerator, begin
to 2147483648
, then my output becomes:
true
4
4294967197
Apparently, It means, that type of end
has changed from int
to unsigned int
, even underlying type of modes
is still the same (i.e. unsigned int
).
Are there some special rules for integral promotions regarding enums?