title: Move semantics and function order evaluation
body: <p>Suppose I have the following:</p>
  
  <pre><code>#include &lt;memory&gt;
  struct A { int x; };
  
  class B {
    B(int x, std::unique_ptr&lt;A&gt; a);
  };
  
  class C : public B {
    C(std::unique_ptr&lt;A&gt; a) : B(a-&gt;x, std::move(a)) {}
  };
  </code></pre>
  
  <p>If I understand the C++ rules about "unspecified order of function parameters" correctly, this code is unsafe. If the second argument to <code>B</code>'s constructor is constructed first using the move constructor, then <code>a</code> now contains a <code>nullptr</code> and the expression <code>a-&gt;x</code> will trigger undefined behavior (likely segfault). If the first argument is constructed first, then everything will work as intended.</p>
  
  <p>If this were a normal function call, we could just create a temporary:</p>
  
  <pre><code>auto x = a-&gt;x
  B b{x, std::move(a)};
  </code></pre>
  
  <p>But in the class initialization list we don't have the freedom to create temporary variables.</p>
  
  <p>Suppose I cannot change <code>B</code>, is there any possible way to accomplish the above? Namely dereferencing and moving a <code>unique_ptr</code> in the same function call expression without creating a temporary?</p>
  
  <p>What if you could change <code>B</code>'s constructor but not add new methods such as <code>setX(int)</code>? Would that help?</p>
  
  <p>Thank you</p>