Skip to content

Commit 0f0170a

Browse files
authored
Merge branch 'main' into rvermeulen/fix-424
2 parents 1d5a2a8 + d087031 commit 0f0170a

15 files changed

+163
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M8-5-2` - `AggregateLiteralEnhancements.qll`:
2+
- recognise aggregate literals initialized with parameters from variadic templates.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A2-10-1`, `RULE-5-3`:
2+
- Reduce false positives by considering point of declaration for local variables.
3+
- Reduce false negatives by considering catch block parameters to be in scope in the catch block.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `M6-5-5`:
2+
- Reduce false positives by no longer considering the taking of a const reference as a modification.
3+
- Improve detection of non-local modification of loop iteration variables to reduce false positives.
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
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| test.cpp:24:8:24:15 | testFlag | Loop control variable testFlag is modified in the loop update expression. |
2+
| test.cpp:47:12:47:12 | y | Loop control variable y is modified in the loop update expression. |

cpp/autosar/test/rules/M6-5-5/test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,27 @@ void test_loop_control_variable_modified_in_expression() {
2424
testFlag = updateFlagWithIncrement(++x)) { // NON_COMPLIANT
2525
}
2626
}
27+
28+
#include <vector>
29+
30+
void test_const_refs(std::vector<int> v) {
31+
std::vector<int>::iterator first = v.begin();
32+
std::vector<int>::iterator last = v.end();
33+
// call to operator!= passes a const reference to first
34+
for (; first != last; first++) { // COMPLIANT
35+
}
36+
}
37+
38+
void update(std::vector<int>::iterator &f, const int &x, int &y) {}
39+
40+
void test_const_refs_update(std::vector<int> v) {
41+
std::vector<int>::iterator last = v.end();
42+
int x = 0;
43+
int y = 0;
44+
// call to operator!= passes a const reference to first
45+
for (std::vector<int>::iterator first = v.begin(); first != last; update(
46+
first, x, // COMPLIANT - first is a loop counter, so can be modified
47+
y)) { // NON_COMPLIANT - y is modified and is not a loop counter
48+
first + 1;
49+
}
50+
}

cpp/autosar/test/rules/M8-5-2/test.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ void test() {
5555
Bar b2{{0}}; // NON_COMPLIANT - missing explicit init, nested zero init
5656
StructNested n{}; // COMPLIANT
5757
StructNested n1 = {}; // COMPLIANT
58-
}
58+
}
59+
60+
#include <initializer_list>
61+
template <class T> bool all_of(std::initializer_list<T>);
62+
63+
template <typename... Args> constexpr bool all_of(Args... args) noexcept {
64+
return all_of({args...}); // COMPLIANT - explicitly initialized via varargs
65+
}
66+
67+
void test_all_of() { all_of(true, false, false); }

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)