title: Underlying type of an unscoped enum?
body: <p>I am observing the following behavior under Visual Studio 2013 (Debug/Win32 compilation). Consider the following c++ code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;climits&gt;
  
  int main(int argc, char *argv[])
  {
    enum { V = (unsigned long long)ULLONG_MAX } E;
    std::cout &lt;&lt; sizeof E &lt;&lt; std::endl;
  
    enum : unsigned long long { W = (unsigned long long)ULLONG_MAX } F;
    std::cout &lt;&lt; sizeof F &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>After compilation this leads to:</p>
  
  <pre><code>$ ./enum.exe
  4
  8
  </code></pre>
  
  <p>If I understand the c++ standard correctly (<a href="https://stackoverflow.com/a/1122128/136285">Standard C++ 7.2/5</a>), 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 <code>int</code> or <code>unsigned int</code>.</p>
  
  <p>So:</p>
  
  <ol>
  <li>Is this is a well known limitation of Visual Studio 2013 (maybe other versions are affected) ?</li>
  <li>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 ?</li>
  </ol>
  
  <hr>
  
  <p>Update: as suggested I reported a problem at:</p>
  
  <ul>
  <li><a href="https://developercommunity.visualstudio.com/content/problem/524018/underlying-type-of-an-unscoped-enum.html" rel="nofollow noreferrer">https://developercommunity.visualstudio.com/content/problem/524018/underlying-type-of-an-unscoped-enum.html</a></li>
  </ul>