Double assignment of the same variable in one expression in C++11

前端 未结 3 1393
慢半拍i
慢半拍i 2021-02-13 20:14

The C++11 standard (5.17, expr.ass) states that

In all cases, the assignment is sequenced after the value computation of the right and left operands, a

3条回答
  •  梦毁少年i
    2021-02-13 20:53

    Yes, there was a change between C++98 and C++11. I believe your example to be well-defined under C++11 rules, while exhibiting undefined behavior under C++98 rules.

    As a simpler example, x = ++x; is undefined in C++98 but is well-defined in C++11. Note that x = x++; is still undefined (side effect of post-increment is unsequenced with the evaluation of the expression, while side effect of pre-increment is sequenced before the same).

提交回复
热议问题