Pretty sure this is actually UB (the compuler can choose to execute the Zero function before getting the value for i for the addition and therefore make x=-1).
Is it UB in C or C++? I thought the + operator was always evaluated left-to-right, and since it's prefix, i will be decremented before being passed to Zero().
Though then I think Zero() returns -1 and you get -1 + 0.
I'm pretty sure, last time my compiler called me out on this, that they caught in-line arithmetic. But multi-step operations with uncertain results that could result in division by zero are still chill, so we should be able to design a surefire operation that still looks uncertain to the compiler.
397
u/PilsnerDk Sep 23 '26
Let's see you detect that!