title: How is "({ expr1; expr2; })" compiled in C++?
body: <p>Something I've used but never understood is the ability in C++ to write code like:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void sideEffect()
  {
      printf("Hello, I'm a side effect\n");
  }
  
  int main()
  {
      printf(({sideEffect(); "Hello side effect\n";}));
      return 0;
  }
  </code></pre>
  
  <p>This prints:</p>
  
  <pre><code>Hello, I'm a side effect
  Hello side effect
  </code></pre>
  
  <p>The <code>({ expr1; expr2; })</code> part seems to run the block and 'replace' the whole thing with the last value.</p>
  
  <p>Is this is just a consequence of operator precedence that I'm not getting, or is there something else going on?</p>
  
  <h2>UPDATE</h2>
  
  <p>Something non-obvious (for me at least) is that the last expression is copied, even if it's returning a reference. I added a simple Foo class that prints when it's being copied to the example above:</p>
  
  <pre><code>...
  
  struct Foo
  {
      Foo()
      {}
      Foo(const Foo&amp;)
      {
          printf("Copying Foo...\n");
      }
  };
  
  const Foo&amp; getFoo()
  {
      static Foo f;
      return f;
  }
  
  int main()
  {
      const Foo&amp; foo = ({sideEffect(); getFoo();});
      return 0;
  }
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>Hello, I'm a side effect
  Copying Foo...
  </code></pre>
  
  <p>If Foo is noncopyable this won't compile</p>