title: Mixing class and struct
body: <p>I'm well aware of the <a href="https://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c">difference between class and struct</a>, however I'm struggling to authoritatively say if this is well defined:</p>
  
  <pre><code>// declare foo (struct)
  struct foo;
  
  // define foo (class)
  class foo {
  };
  
  // instance of foo, claiming to be a struct again! Well defined?
  struct foo bar;
  
  // mixing class and struct like this upsets at least one compiler (names are mangled differently)
  const foo&amp; test() {
     return bar;
  }
  
  int main() {
     test();
     return 0;
  }
  </code></pre>
  
  <p>If this is undefined behaviour can someone point me in the direction of an authoritative (i.e. chapter and verse from ISO) reference? </p>
  
  <p>The compiler with problems handling this (<a href="http://www.forum.nokia.com/Develop/Other_Technologies/Symbian_C++/Tools/" rel="nofollow noreferrer">Carbide 2.7</a>) is relatively old and all the other compilers I've tried it on are perfectly happy with this, but clearly that doesn't prove anything.</p>
  
  <p>My intuition was this ought to be undefined behaviour but I can't find anything to confirm this and I'm surprised that none of the GCC versions or <a href="http://www.comeaucomputing.com/tryitout/" rel="nofollow noreferrer">Comeau</a> so much as warned about it.</p>