I am a bit confused about the way the changes to C++17 affect the rule that you should not modify one variable 2 times between sequence points.
For example is this specified, unspecified or undefined in C++17?
void func(int x, int y);
int x=47;
func(x++,x++);
My guess would be UB.
edit: extra datapoint: clang HEAD in c++2a mode gives
prog.cc:8:11: warning: multiple unsequenced modifications to 'x' [-Wunsequenced]
edit2: same with gcc HEAD in C++2a mode
prog.cc:8:15: warning: operation on 'x' may be undefined [-Wsequence-point]
edit3: with preincrement gcc and clang give different results
The example in your question
int x = 0;
f(x++, x++);
Is now unspecified behavior, rather than undefined behavior. That means that it’s valid code, but what actually happens may differ between compilers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With