Skip to content

Commit f3caa6c

Browse files
committed
M5-2-10: Only report use of ++/-- with arithmetic ops
The rule specifically notes: > The use of increment and decrement operators in combination > with other arithmetic operators is not recommended
1 parent d9f0911 commit f3caa6c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `M5-2-10` - only report use of the increment and decrement operations in conjunction with arithmetic operators, as specified by the rule. Notably we no longer report the expressions of the form `*p++`, which combine increment and dereferencing operations.

cpp/autosar/src/rules/M5-2-10/IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
import cpp
1818
import codingstandards.cpp.autosar
1919

20-
from CrementOperation cop, Operation op, string name
20+
class ArithmeticOperation extends Operation {
21+
ArithmeticOperation() {
22+
this instanceof UnaryArithmeticOperation or this instanceof BinaryArithmeticOperation
23+
}
24+
}
25+
26+
from CrementOperation cop, ArithmeticOperation op, string name
2127
where
2228
not isExcluded(cop) and
2329
not isExcluded(op,

cpp/autosar/test/rules/M5-2-10/test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ void f1() {
66
++l1; // COMPLIANT
77
--l2; // COMPLIANT
88
l3 = l1 * l2;
9+
int *p;
10+
*p++; // COMPLIANT - * is not an arithmetic operator
911
}

0 commit comments

Comments
 (0)