Main Content

AUTOSAR C++14 Rule M5-2-10

The increment (++) and decrement (--) operators shall not be mixed with other operators in an expression

Description

Rule Definition

The increment (++) and decrement (--) operators shall not be mixed with other operators in an expression.

Rationale

Using the increment and decrement operators with other operators in an expressions results in code that is difficult to read. Such code might lead to undefined behavior.

Polyspace Implementation

Polyspace® flags an expression if it contains the increment or decrement operators mixed with other operators. If an expression contains multiple increment or decrement operators mixed with other operators, Polyspace flags the first increment or decrement operator.

Troubleshooting

If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

void foo(int a, int b){
	int c = ++a + b--; //Noncompliant
	if(--c + --a - ++b){ //Noncompliant
		//...
	}
}

Polyspace flags the mixing of the ++ and -- operators with other mathematical operators in an expression.

Check Information

Group: Expressions
Category: Required, Automated

Version History

Introduced in R2019a