title: Copy constructor is called instead of move constructor - why?
body: <p>I have this code, taken from here by the way <a href="http://www.cplusplus.com/doc/tutorial/classes2/" rel="nofollow noreferrer">http://www.cplusplus.com/doc/tutorial/classes2/</a></p>
  
  <pre><code>// move constructor/assignment
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;utility&gt;
  using namespace std;
  
  class Example6
  {
      string* ptr;
  public:
      Example6(const string&amp; str) :
              ptr(new string(str))
      {
          cout &lt;&lt; "DONT   MOVE " &lt;&lt; '\n';
      }
      ~Example6()
      {
          delete ptr;
      }
  // move constructor
      Example6(Example6&amp;&amp; x) :
              ptr(x.ptr)
      {
          cout &lt;&lt; "MOVE " &lt;&lt; '\n';
          x.ptr = nullptr;
      }
  // move assignment
      Example6&amp; operator=(Example6&amp;&amp; x)
      {
          delete ptr;
          ptr = x.ptr;
          x.ptr = nullptr;
          return *this;
      }
  // access content:
      const string&amp; content() const
      {
          return *ptr;
      }
  // addition:
      Example6 operator+(const Example6&amp; rhs)
      {
          return Example6(content() + rhs.content());
      }
  };
  
  int main()
  {
      Example6 foo("Exam");
      Example6 bar = Example6("ple"); // move-construction
  
      foo = foo + bar; // move-assignment
  
      cout &lt;&lt; "foo's content: " &lt;&lt; foo.content() &lt;&lt; '\n';
      return 0;
  }
  </code></pre>
  
  <p>I only added output in constructor to see which is being called. To my surprise it is always the first one, copy constructor. Why does it happen? I did some research and found some info about elision. Is it somehow possible to prevent it and always call move constructor?</p>
  
  <p>Also, as a side note, as I said this code is from cplusplus.com. However, I read about move semantics in some other places and I wonder if this move constructor here is done right. Shouldn't it call</p>
  
  <pre><code>  ptr(move(x.ptr))
  </code></pre>
  
  <p>instead of just </p>
  
  <pre><code>ptr(x.ptr)
  </code></pre>
  
  <p>The way I understand this, if we use the second option, then we are calling copy constructor of string, instead of move, because x is rvalue reference that has a name, so it is really lvalue and we need to use move to cast it to be rvalue. Do i miss something, or is it really tutorial's mistake?
  Btw, adding move doesn't solve my first problem.</p>