title: Do C++11 compilers turn local variables into rvalues when they can during code optimization?
body: <p>Sometimes it's wise to split complicated or long expressions into multiple steps, for example (the 2nd version isn't more clear, but it's just an example):</p>
  
  <pre><code>return object1(object2(object3(x)));
  </code></pre>
  
  <p>can be written as:</p>
  
  <pre><code>object3 a(x);
  object2 b(a);
  object1 c(b);
  return c;
  </code></pre>
  
  <p>Assuming all 3 classes implement constructors that take rvalue as a parameter, the first version might be faster, because temporary objects are passed and can be moved. I'm assuming that in the 2nd version, the local variables are considered to be lvalues. But if the variables aren't later used, do C++11 compilers optimize the code so the variables are considered to be rvalues and both versions work exactly the same? I'm mostly interested in Visual Studio 2013's C++ compiler, but I'm also happy know how the GCC compiler behaves in this matter.</p>
  
  <p>Thanks,
  Michal</p>