title: Shift operands sequenced in C++17
body: <p>I read in the C++17 Standard $8.5.7.4:</p>
  <blockquote>
  <p>The expression E1 is sequenced before the expression E2.</p>
  </blockquote>
  <p>for shift operators.</p>
  <p>Also <a href="https://en.cppreference.com/w/cpp/language/eval_order" rel="nofollow noreferrer">cppreference</a> rule 19 says:</p>
  <blockquote>
  <p>In a shift operator expression E1&lt;&gt;E2, every value computation and side-effect of E1 is sequenced before every value computation and side effect of E2</p>
  </blockquote>
  <p>But when I try to compile the following code with gcc 7.3.0 or clang 6.0.0</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      int i = 5;
      cout &lt;&lt; (i++ &lt;&lt; i) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  <p>I get the following gcc warning:</p>
  <pre><code>../src/Cpp_shift.cpp: In function ‘int main()’:
  ../src/Cpp_shift.cpp:6:12: warning: operation on ‘i’ may be undefined [-Wsequence-point]
    cout &lt;&lt; (i++ &lt;&lt; i) &lt;&lt; endl;
             ~^~
  </code></pre>
  <p>The clang warning is:</p>
  <pre><code>warning: unsequenced modification and access to 'i' [-Wunsequenced]
  </code></pre>
  <p>I used the following commands to compile:</p>
  <pre><code>g++ -std=c++17 ../src/Cpp_shift.cpp -o Cpp_shift -Wall
  clang++ -std=c++17 ../src/Cpp_shift.cpp -o Cpp_shift -Wall
  </code></pre>
  <p>I get the expected <code>320</code> as output in both cases ( 5 * 2 ^ 6 )</p>
  <p>Can someone explain why I get this warning? Did I overlook something? I also read <a href="https://stackoverflow.com/questions/38501587/what-are-the-evaluation-order-guarantees-introduced-by-c17">this</a> related question, but it does not answer my question.</p>
  <p>edit: all other variants <code>++i &lt;&lt; i</code>, <code>i &lt;&lt; ++i</code> and <code>i &lt;&lt; i++</code> result in the same warning.</p>
  <p>edit2: <code>(i &lt;&lt; ++i)</code> results in <code>320</code> for clang (correct) and <code>384</code> for gcc (incorrect). It seems that gcc gives a wrong result if the <code>++</code> is at <code>E2</code>, <code>(i &lt;&lt; i++)</code> also gives a wrong result.</p>