title: Why does the expression a = a + b - ( b = a ) give a sequence point warning in c++?
body: <p>Following is the test code:</p>
  
  <pre><code>int main()
  {
      int a = 3;
      int b = 4;
      a = a + b - (b = a); 
  
      cout &lt;&lt; "a :" &lt;&lt; a &lt;&lt; " " &lt;&lt; "b :" &lt;&lt; b &lt;&lt; "\n";    
      return 0;
  }
  </code></pre>
  
  <p>Compiling this gives the following warning:</p>
  
  <pre><code>&gt; $ g++ -Wall -o test test.cpp test.cpp: In function ‘int main()’:
  &gt; test.cpp:11:21: warning: operation on ‘b’ may be undefined
  &gt; [-Wsequence-point]
  </code></pre>
  
  <p>Why can the operation be undefined? </p>
  
  <p>According to my understanding, first the subexpression <code>(b = a)</code> should be evaluated because of higher precedence of (), thus setting b = a. Then, since '+' and '-' have same precedence, the expression would be evaluated left-associatively. Thus, <code>a + b</code> should be evaluated next, and finally the result of <code>(b = a)</code> should be subtracted from <code>a + b</code>. I can't see any <a href="http://en.wikipedia.org/wiki/Sequence_point" rel="noreferrer">sequence-point rule</a> being violated here.</p>