title: RVO overwriting value in parameter before return
body: <p>Compiling the following with xlC on AIX results in code that prints "2 2". On Linux with gcc and clang it reliably produces "3 3".</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct Numbers
  {
      Numbers() : a(0) , b(0) { } 
      Numbers(int a, int b) : a(a), b(b) { }
  
      int a;
      int b;
  };
  
  Numbers combine(const Numbers&amp; a, const Numbers&amp; b)
  {
      Numbers x;
      x.a = a.a + b.a;
      x.b = a.b + b.b;
      return x;
  }
  
  Numbers make()
  {
      Numbers a(1, 1);
      Numbers b(2, 2);
  
      a = combine(a, b);
      return a;
  }
  
  int main()
  {
      Numbers a = make();
      std::cerr &lt;&lt; a.a &lt;&lt; " " &lt;&lt; a.b &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>It looks to me like AIX is applying RVO to the return value of <code>combine</code>, so when I create <code>Numbers x</code>, it ends up overwriting my parameter <code>a</code> with the default initialised <code>x</code>.</p>
  
  <p>Am I invoking some undefined behaviour here? I would expect that no modifications are made to <code>a</code> until after <code>combine(a, b)</code> has been evaluated and assigned to <code>a</code>.</p>
  
  <p>This is with:
  IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72)
  Version: 12.01.0000.0012</p>