title: Class with all automatically-generated constructors/operators deleted can still be returned from a function?
body: <p>Recently, I came across this <a href="https://stackoverflow.com/a/46899787/1021959">answer</a> which describes how to initialize a <code>std::array</code> of non-default-constructible elements.  I was not so surprised because that answer clearly doesn't do any default-constructing.</p>
  
  <p>Instead, it is constructing a temporary <code>std::array</code> using aggregate initialization, then moving (if the move constructor is available) or copying into the named variable when the function returns.  So we only need either the move constructor or copy constructor to be available.</p>
  
  <p><em>Or so I thought...</em></p>
  
  <p>Then came this piece of code which confounded me:</p>
  
  <pre><code>struct foo {
      int x;
      foo(int x) : x(x) {}
      foo() = delete;
      foo(const foo&amp;) = delete;
      foo&amp; operator=(const foo&amp;) = delete;
      foo(foo&amp;&amp;) = delete;
      foo&amp; operator=(foo&amp;&amp;) = delete;
  };
  
  foo make_foo(int x) {
      return foo(x);
  }
  
  int main() {
      foo f = make_foo(1);
      foo g(make_foo(2));
  }
  </code></pre>
  
  <p>All the five special member constructors/operators are explicitly deleted, so now I shouldn't be able to construct my object from a return value, correct?</p>
  
  <p><strong>Wrong.</strong></p>
  
  <p>To my surprise, this compiles in gcc (with C++17)!</p>
  
  <p>Why does this compile?  Clearly to return a <code>foo</code> from the function <code>make_foo()</code>, we have to construct a <code>foo</code>.  Which means that in the <code>main()</code> function we are assigning or constructing a <code>foo</code> from the returned <code>foo</code>.  How is that possible?!</p>