这个 post-increment 语句会导致未定义的行为吗?

Does this post-increment statement result in undefined behaviour?

在使用较新版本的 GCC 构建程序时,我发现代码中存在问题。

count[i] = count[i]++;

此代码适用于较旧版本的 GCC (2.95),但不适用于较新版本 (4.8)。

所以我怀疑此声明会导致未定义的行为,我说得对吗?或者有更好的术语来描述这个问题吗?

确实,这是未定义的行为。

int i = 2;
i = i++; // is i assigned to be 2 or 3?

这实际上被指定为未定义的行为,因为每个编译器都定义了自己的操作顺序,如下所述:https://en.cppreference.com/w/cpp/language/eval_order

Order of evaluation of the operands of almost all C++ operators (including the order of evaluation of function arguments in a function-call expression and the order of evaluation of the subexpressions within any expression) is unspecified. The compiler can evaluate operands in any order, and may choose another order when the same expression is evaluated again.

cppreference中的increment/decrement页面居然有警告:https://en.cppreference.com/w/cpp/language/operator_incdec

Because of the side-effects involved, built-in increment and decrement operators must be used with care to avoid undefined behavior due to violations of sequencing rules.