-2

This is undefined behavior, right? Double assignment in the same sequence point?

int i = 0;
i = ++i;
Carbon
  • 3,828
  • 3
  • 24
  • 51

1 Answers1

2

i = ++i; is undefined in all C++ standards prior to C++11.

Note that cohorts of similar expressions using the postfix increments are not defined until C++17.

Both are defined if ++ is overloaded, which is a moot point here as the incrementee is a primitive.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483