title: Difference observed between MSVC14.1 and gcc8.3 when a destructor call for an automatic variable amends a function return value
body: <p>Consider the following (to be compiled with C++14)</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  // Foo adds an element to a std::vector passed by reference
  // on construction in the destructor
  struct Foo {
      Foo(std::vector&lt;double&gt;&amp; v) : m_v(v){
      }
      ~Foo(){
          m_v.push_back(1.0);
      }
      std::vector&lt;double&gt;&amp; m_v;
  };
  
  std::vector&lt;double&gt; bar(){
      std::vector&lt;double&gt; ret;
      Foo foo(ret);
      return ret;
  }
  
  int main(){
      std::cout &lt;&lt; bar().size() &lt;&lt; &quot;\n&quot;;
  }
  </code></pre>
  <p>In gcc8.3 the output is <code>1</code>, which means that <code>foo</code>s destructor has an effect on the returned vector.</p>
  <p>In MSVC14.1 the output is <code>0</code>. You can force the output to be the same as gcc8.3 by replacing the line <code>Foo foo(ret);</code> with <code>{Foo foo(ret);}</code> (i.e. by forcing the scope).</p>
  <p>I don't <em>think</em> this is dangling reference undefined behaviour (because <code>ret</code> is declared before <code>foo</code>) but rather that this could be a bug in MSVC14.1 (and I will create a bug report if so). Does anyone know for sure?</p>
  <p>See <a href="https://ideone.com/pnxWuJ" rel="noreferrer">https://ideone.com/pnxWuJ</a></p>