title: Constructor call sequence different on GCC and clang
body: <p>I have the following program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #define PRINT_LOCATION()\
      do { std::cout &lt;&lt; __PRETTY_FUNCTION__ &lt;&lt; "\n"; } while (false)
  
  struct foo
  {
      int val;
  
      foo()
          : val(1)
      {
          PRINT_LOCATION();
      }
  
      foo(const foo&amp; other)
          : val(other.val * 2)
      {
          PRINT_LOCATION();
      }
  
      foo(foo&amp;&amp; other)
          : val(other.val * 2)
      {
          PRINT_LOCATION();
      }
  };
  
  int main()
  {
      foo f{foo{foo{foo{}}}};
  
      std::cout &lt;&lt; "value = " &lt;&lt; f.val &lt;&lt; "\n";
  
      if (f.val == 1)
          throw f;
  }
  </code></pre>
  
  <p>Compilation and execution:</p>
  
  <pre><code>[mkc /tmp]$ g++ -Wall -Wextra -pedantic -std=c++14 -O0 -o a.out main.cpp
  [mkc /tmp]$ ./a.out 
  foo::foo()
  value = 1
  foo::foo(foo&amp;&amp;)
  terminate called after throwing an instance of 'foo'
  Aborted (core dumped)
  [mkc /tmp]$ clang++ -Wall -Wextra -pedantic -std=c++14 -O0 -o a.out main.cpp
  [mkc /tmp]$ ./a.out 
  foo::foo()
  foo::foo(foo &amp;&amp;)
  foo::foo(foo &amp;&amp;)
  value = 4
  [mkc /tmp]$
  </code></pre>
  
  <p>I know that the compiler is allowed to remove some constructor calls, but isn't it only allowed to do it when there are no side effects? It looks like Clang is correct here, is it a bug in GCC?</p>