title: Does the behavior of guaranteed copy elision depend on existence of user-defined copy constructor?
body: <p>The following code behaves differently with or without user-defined copy constructor <a href="https://wandbox.org/permlink/46p36ZShdZub7WFM" rel="noreferrer">under GCC 8.0.1</a>:</p>
  
  <pre><code>#include &lt;cassert&gt;
  
  struct S {
      int i;
      int *p;
      S() : i(0), p(&amp;i) {}
      // S(const S &amp;s) : i(s.i), p(&amp;i) {}  // #1
      // S(const S &amp;s) : i(s.i), p(s.p) {} // #2
      // S(const S &amp;s) = delete;           // #3
  };
  
  S make_S() {return S{};}
  
  int main()
  {
      S s = make_S();
      assert(s.p == &amp;s.i);
  }
  </code></pre>
  
  <p>With either of the commented user-defined copy constructors (even with #2, the one performing a simple shallow copy), the assertion will not fail, which means <a href="https://stackoverflow.com/questions/38043319/how-does-guaranteed-copy-elision-work">guaranteed copy elision</a> works as expected.</p>
  
  <p>However, without any user-defined copy constructor, the assertion fails, which means the object <code>s</code> in <code>main</code> function is not default-constructed. Why does this happen? Doesn't guaranteed copy elision perform here?</p>