title: Difference between C++14 and C++17 using: `*p++ = *p`
body: <p>While writing some code, I came across a problem where values I set were being set wrong. I eventually found the culprit line and while testing around found that it behaved differently on C++14 and C++17. The code is as follows:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cstdint&gt;
  #include &lt;cstring&gt;
  
  int main()
  {
      uint8_t *p = new uint8_t[3];
      memset(p, 0x00, 1);
      p++;
      memset(p, 0xF0, 1);
      p++;
      memset(p, 0xFF, 1);
      p--;
      p--;
  
      // This line in particular
      *p++ = *p;
  
      *p++ = 0x0F;
  
      p--;
      p--;
  
      printf("Position 0 has value %u\n", *p);
      p++;
      printf("Position 1 has value %u\n", *p);
      p++;
      printf("Position 2 has value %u\n", *p);
  
      return 0;
  }
  </code></pre>
  
  <p>On C++14 it prints:</p>
  
  <pre><code>Position 0 has value 240
  Position 1 has value 15
  Position 2 has value 255
  </code></pre>
  
  <p>And on C++17 it prints:</p>
  
  <pre><code>Position 0 has value 0
  Position 1 has value 15
  Position 2 has value 255
  </code></pre>
  
  <p>I'm curious why it acts differently on different C++ versions. It looks as though on C++14 the <code>*p</code> right side of the assignment is evaluated after the <code>++</code>. Did this change? And if the <code>++</code> has precedence, why does it not happen before the dereference on the left side of the assignment operator?</p>