-2

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

int i = 0;
i = ++i;
Carbon
  • 3,054
  • 1
  • 21
  • 43

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
  • 227,678
  • 33
  • 352
  • 470