title: Location of compiler-generated class methods
body: <p><strong>EDIT:</strong> Added a field to the example class to make it non-trivially-destructible, and a clarification that it was not meant to be the point of the question.</p>
  <p>Consider a simple class with no user-declared destructor, e.g.</p>
  <pre><code>struct A {
      std::string s;
  };
  </code></pre>
  <p>Note that the actual field doesn't matter - it's only here to make the classes non-trivially-destructible, so that it doesn't distract. In other words, imagine it's a &quot;normal&quot; everyday class, not exceptional in any way.</p>
  <p>In this case, the compiler is going to generate the destructor for us. The overall question is: when exactly is this destructor generated and where is its body placed?</p>
  <p>To be more specific:</p>
  <ul>
  <li>does the compiler actually generate any source code? and if so, where is this source code placed?</li>
  <li>if no actual source code is generated, and we move directly to some internal represention / machine code, the questions are the same - when is the generation triggered, and where is its representation stored?</li>
  </ul>
  <p>The practical motivation for this question is the issue of using unique_ptr with incomplete types, as in <a href="https://stackoverflow.com/questions/9954518/stdunique-ptr-with-an-incomplete-type-wont-compile">std::unique_ptr with an incomplete type won&#39;t compile</a> or related questions. The solution is to prevent the compiler from generating the destructor on its own, and to precisely control the location by ourselves, so that the generation happens only after the complete type definition has been seen. And while most answers mention that it's generated &quot;too early&quot;, I couldn't find any specifics on when exactly does it happen.</p>
  <p>I'd speculate that the destructor (and other auto-generated members) would be placed at the end of class definition, right before the closing brace, but it's just a guess.</p>
  <p>Any normative references would be much appreciated as well.</p>
  <p>Please also note that this question is not about the contents of the destructor - it's not about what it does, it's about where it's located.</p>