Skip to content

Commit d087031

Browse files
authored
Merge pull request #489 from github/lcartey/m5-2-10-arith-only
M5-2-10: Only report the use of `++`/`--` with arithmetic operations
2 parents a4ca321 + 3213f1c commit d087031

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M5-2-10` - `IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql`:
2+
- 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
import cpp
1818
import codingstandards.cpp.autosar
19+
import codingstandards.cpp.Expr
1920

20-
from CrementOperation cop, Operation op, string name
21+
from CrementOperation cop, ArithmeticOperation op, string name
2122
where
2223
not isExcluded(cop) and
2324
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
}

cpp/common/src/codingstandards/cpp/Expr.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import cpp
22
private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
33
import codingstandards.cpp.AccessPath
44

5+
/**
6+
* A unary or binary arithmetic operation.
7+
*/
8+
class ArithmeticOperation extends Operation {
9+
ArithmeticOperation() {
10+
this instanceof UnaryArithmeticOperation or this instanceof BinaryArithmeticOperation
11+
}
12+
}
13+
514
/** A full expression as defined in [intro.execution] of N3797. */
615
class FullExpr extends Expr {
716
FullExpr() {

0 commit comments

Comments
 (0)