title: C++11: Unsequenced modification and access to variable (streams)
body: <p>I recently wanted to get a better feeling for the return values of the ++i and the i++ operator. So I created this small program here:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main()
  {
      int i = 0;
      int j = 0;
      cout &lt;&lt; "i++ " &lt;&lt; i++ &lt;&lt; " i " &lt;&lt; i &lt;&lt; endl;
      cout &lt;&lt; "++j " &lt;&lt; ++j &lt;&lt; " j " &lt;&lt; j &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Now looking at the code I would expect that when I execute it I get the following result:</p>
  
  <pre><code>i++ 0 i 1
  ++j 1 j 1
  </code></pre>
  
  <p>Compiling the above snippet with llvm/clang 3.5 (Apple LLVM version 6.0 (clang-600.0.51)) yields the following warning:</p>
  
  <pre><code>main.cpp:8:23: warning: unsequenced modification and access to 'j'
        [-Wunsequenced]
      cout &lt;&lt; "++j " &lt;&lt; ++j &lt;&lt; " j " &lt;&lt; j &lt;&lt; endl;
                        ^               ~
  1 warning generated.
  </code></pre>
  
  <p>What does that mean in this context? The only <a href="http://www.bionoren.com/blog/2013/07/unsequenced-modification-and-access/" rel="nofollow noreferrer">blog post I found</a> was not so helpful since I can't imagine a reordering of the output somehow. 
  What would the output of such a reordering look like? </p>
  
  <p>There's also a couple of similar questions here. The only good question on the subject I found was this <a href="https://stackoverflow.com/questions/21066593/sequence-points-and-side-effects-quiet-change-in-c11/21066791">one</a>. But I don't understand how this would create the compiler warning above. </p>
  
  <p>Compiling the code from above with gcc 4.9 (the flag -std=c++11 was enabled) didn't show this warning at all.</p>