Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, i is evaluated more than once in an unsequenced manner, and so the behavior of the expression is undefined.

...

Attempting to modify an object in an unsequenced or indeterminately sequenced evaluation may cause that object to take on an unexpected value, which can lead to unexpected program behavior.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP50-CPP

Medium

Probable

Medium

P8

L2

Automated Detection

Tool

Version

Checker

Description

Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC++-EXP50
Clang
Include Page
Clang_V
Clang_V
-WunsequencedCan detect simple violations of this rule where path-sensitive analysis is not required
Compass/ROSE

 

 

Can detect simple violations of this rule. It needs to examine each
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

LANG.STRUCT.SE.DEC
LANG.STRUCT.SE.INC

Side Effects in Expression with Decrement
Side Effects in Expression with Increment

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

Coverity

Include Page
Coverity_V
Coverity_V

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

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.EXP30

Fully implemented

GCC
Include Page
GCC_V
GCC_V

 


Can detect violations of this rule when the -Wsequence-point flag is used

LDRA tool suite
Helix QAC

Include Page

LDRA

Helix QAC_V

LDRA

Helix QAC_V

35 D, 1 Q, 9 S, 134 S, 67 D, 72 D

Partially implemented

Parasoft C/C++test9.5JSF-204.1{a,b,c,d,g}Fully implementedPRQA QA-C++ Include PagePRQA QA-C++_VPRQA QA-C++_V3220, 3221, 3222, 3223 

C++3220, C++3221, C++3222, C++3223, C++3228


Klocwork
Include Page
Klocwork_V
Klocwork_V
PORTING.VAR.EFFECTS
CERT.EXPR.PARENS
MISRA.EXPR.PARENS.INSUFFICIENT
MISRA.INCR_DECR.OTHER

LDRA tool suite
Include Page
LDRA_V
LDRA_V

35 D, 1 Q, 9 S, 134 S, 67 D, 72 D

Partially implemented

Parasoft C/C++test
Include Page
Parasoft_V
Parasoft_V

CERT_CPP-EXP50-a
CERT_CPP-EXP50-b
CERT_CPP-EXP50-c
CERT_CPP-EXP50-d
CERT_CPP-EXP50-e
CERT_CPP-EXP50-f

The value of an expression shall be the same under any order of evaluation that the standard permits
Don't write code that depends on the order of evaluation of function arguments
Don't write code that depends on the order of evaluation of function designator and function arguments
Don't write code that depends on the order of evaluation of expression that involves a function call
Between sequence points an object shall have its stored value modified at most once by the evaluation of an expression
Don't write code that depends on the order of evaluation of function calls

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C++: EXP50-CPPChecks for situations where expression value depends on order of evaluation (rule fully covered).
PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V521, V708
SonarQube C/C++ Plugin
Include Page
SonarQube C/C++ Plugin_V
SonarQube C/C++ Plugin_V
IncAndDecMixedWithOtherOperatorsPartially implemented
Splint
Include Page
Splint_V
Splint_V

 

 



Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

Bibliography

[ISO/IEC 14882-2014]Subclause 1.9, "Program Execution"
[MISRA
08
2008]Rule 5-0-1 (Required)

...


...

Image Modified Image Modified Image Modified