title: C++11 Enum forward causes "underlying type mismatch"
body: <p>I'm working in C++11 and including an h file implemented in C++03. In the h file I'm including there's an enum <code>Foo</code> defined. I want to declare a forward to it in <code>code.h</code> and use it in <code>code.cpp</code>:</p>
  
  <p>header.h:</p>
  
  <pre><code>enum Foo {A=1};
  </code></pre>
  
  <p>code.h:</p>
  
  <pre><code>enum Foo : int; // also tried : unsigned int, long, short, unsigned short, char, unsigned char
  void bar(Foo foo);
  </code></pre>
  
  <p>code.cpp:</p>
  
  <pre><code>#include header.h
  void bar(Foo foo) { }
  </code></pre>
  
  <p>This is the error I get when I compile (tested g++ 4.8.5 and g++ 5.3.1):</p>
  
  <pre><code>In file included from code.cpp:2:0:
  header.h:1:6: error: underlying type mismatch in enum ‘enum Foo’
   enum Foo {A=1};
        ^
  In file included from code.cpp:1:0:
  code.h:3:12: error: previous definition here
   enum Foo : int;
  </code></pre>
  
  <p>I can fix this error if I change header.h to:</p>
  
  <pre><code>enum Foo : int {A=1};
  </code></pre>
  
  <p>But I don't own that header and can't change it. Taking the error at face value, it sounds like all I need to know is what type g++ uses for enums which don't specify underlying type, then use that type in my forward.</p>
  
  <p><a href="http://cpp.sh/4liwz" rel="noreferrer">Even this simple example doesn't work</a> :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;type_traits&gt;
  
  enum Foo {A=1};
  enum Foo : unsigned; // : std::underlying_type&lt;Foo&gt;::type also doesn't work
  
  int main()
  {
  
    std::cout &lt;&lt; "Hello, world\n";
  }
  </code></pre>