
...
Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. ... The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, and they are not potentially concurrent, the behavior is undefined. ... When calling a function (whether or not the function is inline), every value computation and side effect associated with any argument expression, or with the postfix expression designating the called function, is sequenced before execution of every expression or statement in the body of the called function. ... Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function. Several contexts in C++ cause evaluation of a function call, even though no corresponding function call syntax appears in the translation unit. ... The sequencing constraints on the execution of the called function (as described above) are features of the function calls as evaluated, whatever the syntax of the expression that calls the function might be.
Do not allow the same scalar object to appear in side effects or value computations in both halves of an unsequenced or indeterminately sequenced operation.
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Axivion Bauhaus Suite |
| CertC++-EXP50 | |||||||
Clang |
| -Wunsequenced | Can detect simple violations of this rule where path-sensitive analysis is not required | ||||||
CodeSonar |
| LANG.STRUCT.SE.DEC | Side Effects in Expression with Decrement | ||||||
Compass/ROSE | Can detect simple violations of this rule. It needs to examine each expression and make sure that no variable is modified twice in the expression. It also must check that no variable is modified once, then read elsewhere, with the single exception that a variable may appear on both the left and right of an assignment operator | ||||||||
| EVALUATION_ORDER | Can detect the specific instance where a statement contains multiple side effects on the same value with an undefined evaluation order because, with different compiler flags or different compilers or platforms, the statement may behave differently | |||||||
| CC2.EXP30 | Fully implemented | |||||||
GCC |
| Can detect violations of this rule when the | |||||||
Helix QAC |
| C++3220, C++3221, C++3222, C++3223, C++3228 | |||||||
Klocwork |
| PORTING.VAR.EFFECTS CERT.EXPR.PARENS MISRA.EXPR.PARENS.INSUFFICIENT MISRA.INCR_DECR.OTHER | |||||||
LDRA tool suite |
| 35 D, 1 Q, 9 S, 134 S, 67 D, 72 D | Partially implemented | ||||||
Parasoft C/C++test |
| CERT_CPP-EXP50-a | The value of an expression shall be the same under any order of evaluation that the standard permits | ||||||
Polyspace Bug Finder |
| CERT C++: EXP50-CPP | Checks for situations where expression value depends on order of evaluation (rule fully covered). | ||||||
PVS-Studio |
| V521, V708 | |||||||
SonarQube C/C++ Plugin |
| IncAndDecMixedWithOtherOperators | Partially implemented | ||||||
Splint |
|
...
[ISO/IEC 14882-2014] | Subclause 1.9, "Program Execution" |
[MISRA 2008] | Rule 5-0-1 (Required) |
...