title: What made i = i++ + 1; legal in C++17?
body: <p>Before you start yelling undefined behaviour, this is <em>explicitly</em> listed in <a href="https://timsong-cpp.github.io/cppwp/n4659/intro.execution#17" rel="noreferrer">N4659 (C++17)</a></p>
  
  <pre><code>  i = i++ + 1;        // the value of i is incremented
  </code></pre>
  
  <p>Yet in <a href="https://timsong-cpp.github.io/cppwp/n3337/intro.execution#15" rel="noreferrer">N3337 (C++11)</a></p>
  
  <pre><code>  i = i++ + 1;        // the behavior is undefined
  </code></pre>
  
  <p>What changed?</p>
  
  <p>From what I can gather, from <a href="https://timsong-cpp.github.io/cppwp/n4659/intro.execution#17" rel="noreferrer">[N4659 basic.exec]</a></p>
  
  <blockquote>
    <p>Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [...] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a memory location is unsequenced relative to either another side effect on the same memory location or a value computation using the value of any object in the same memory location, and they are not potentially concurrent, the behavior is undefined.</p>
  </blockquote>
  
  <p>Where <em>value</em> is defined at <a href="https://timsong-cpp.github.io/cppwp/n4659/basic.types#4" rel="noreferrer">[N4659 basic.type]</a></p>
  
  <blockquote>
    <p>For trivially copyable types, the value representation is a set of bits in the object representation that determines a <em>value</em>, which is one discrete element of an implementation-defined set of values</p>
  </blockquote>
  
  <p>From <a href="https://timsong-cpp.github.io/cppwp/n3337/intro.execution#15" rel="noreferrer">[N3337 basic.exec]</a></p>
  
  <blockquote>
    <p>Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [...] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.</p>
  </blockquote>
  
  <p>Likewise, value is defined at <a href="https://timsong-cpp.github.io/cppwp/n3337/basic.types#4" rel="noreferrer">[N3337 basic.type]</a></p>
  
  <blockquote>
    <p>For trivially copyable types, the value representation is a set of bits in the object representation that determines a <em>value</em>, which is one discrete element of an implementation-defined set of values.</p>
  </blockquote>
  
  <p>They are identical except mention of concurrency which doesn't matter, and with the usage of <em>memory location</em> instead of <em>scalar object</em>, where</p>
  
  <blockquote>
    <p>Arithmetic types, enumeration types, pointer types, pointer to member types, <code>std::nullptr_t</code>, and cv-qualified versions of these types are collectively called scalar types.</p>
  </blockquote>
  
  <p>Which doesn't affect the example.</p>
  
  <p>From <a href="https://timsong-cpp.github.io/cppwp/n4659/expr.ass#1" rel="noreferrer">[N4659 expr.ass]</a></p>
  
  <blockquote>
    <p>The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand. The result in all cases is a bit-field if the left operand is a bit-field. In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression. The right operand is sequenced before the left operand.</p>
  </blockquote>
  
  <p>From <a href="https://timsong-cpp.github.io/cppwp/n3337/expr.ass#1" rel="noreferrer">[N3337 expr.ass]</a></p>
  
  <blockquote>
    <p>The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand. The result in all cases is a bit-field if the left operand is a bit-field. In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression.</p>
  </blockquote>
  
  <p>The only difference being the last sentence being absent in N3337.</p>
  
  <p>The last sentence however, shouldn't have any importance as the left operand <code>i</code> is neither <em>"another side effect"</em> nor <em>"using the value of the same scalar object"</em> as the <em>id-expression</em> is a lvalue.</p>