Search code examples
c++language-lawyerundefined-behaviorside-effects

Interaction between post-decrement and logical operators


For example, in the following expression

i-- && expr

Will i be already decremented when evaluating expr? Language-lawyers would be adapt here.


Solution

  • If the && operator is the built-in operator, then yes. From [expr.log.and]/2:

    If the second expression is evaluated, every value computation and side effect associated with the first expression is sequenced before every value computation and side effect associated with the second expression.

    If the operator is overloaded, it is a normal function call, and the order of evaluation of the function call arguments is unspecified.