title: C++ nrvo/copy elision with return statement in parentheses
body: <p>i was fooling around with the following code and got different results using my visual studio 2017 application and two different online compilers. in release mode visual studio does elide the copy/move in both cases, while the two online compilers just do it in case of the unparenthesized return statement. my question is: who is right and more importantly what are the underlaying rules. (i know you can use the parentheses in conjunction with the <code>decltype(auto)</code>syntax. but this is not the current usecase).</p>
  
  <p>example code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  
  struct Foo
  {
      Foo() { std::cout &lt;&lt; "default constructor" &lt;&lt; std::endl; }
      Foo(const Foo&amp; rhs) { std::cout &lt;&lt; "copy constructor" &lt;&lt; std::endl; }
      Foo(Foo&amp;&amp; rhs) { std::cout &lt;&lt; "move constructor" &lt;&lt; std::endl; }
      Foo&amp; operator=(const Foo&amp; rhs) { std::cout &lt;&lt; "copy assignment" &lt;&lt; std::endl; return *this; }
      Foo&amp; operator=(Foo&amp;&amp; rhs) { std::cout &lt;&lt; "move assignment" &lt;&lt; std::endl; return *this; }
  };
  
  Foo foo_normal()
  {
      Foo a{};
      return a;
  }
  
  Foo foo_parentheses()
  {
      Foo a{};
      return (a);
  }
  
  int main()
  {
      auto a = foo_normal();
      auto b = foo_parentheses();
      std::getchar();
  }
  </code></pre>
  
  <p>online compiler 1:
  <a href="http://cpp.sh/75bux" rel="nofollow noreferrer">http://cpp.sh/75bux</a></p>
  
  <p>online compiler 2:
  <a href="http://coliru.stacked-crooked.com/a/c266852b9e1712f3" rel="nofollow noreferrer">http://coliru.stacked-crooked.com/a/c266852b9e1712f3</a></p>
  
  <p>the output for visual studio in release mode is:</p>
  
  <pre><code>default constructor
  default constructor
  </code></pre>
  
  <p>in the two other compilers the output is:</p>
  
  <pre><code>default constructor
  default constructor
  move constructor
  </code></pre>