I am observing the following behavior under Visual Studio 2013 (Debug/Win32 compilation). Consider the following c++ code:
#include <iostream>
#include <climits>
int main(int argc, char *argv[])
{
enum { V = (unsigned long long)ULLONG_MAX } E;
std::cout << sizeof E << std::endl;
enum : unsigned long long { W = (unsigned long long)ULLONG_MAX } F;
std::cout << sizeof F << std::endl;
return 0;
}
After compilation this leads to:
$ ./enum.exe
4
8
If I understand the c++ standard correctly (Standard C++ 7.2/5), this is an invalid c++ behavior. In this case, I should not be required to define the underlying type explicitly, since the value of an enumerator cannot fit in an int
or unsigned int
.
So:
- Is this is a well known limitation of Visual Studio 2013 (maybe other versions are affected) ?
- Is there a way to force the compiler to use a proper underlying type for a c++98 style enum ? Or am I required to switch to c++11 notation with fixed-type ?
Update: as suggested I reported a problem at: