Skip to content

Commit 65b8539

Browse files
authored
Merge branch 'main' into rvermeulen/fix-466
2 parents 591c755 + 5a54165 commit 65b8539

14 files changed

+41
-9
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M9-3-3` - `MemberFunctionConstIfPossible.ql`, `MemberFunctionStaticIfPossible.ql`:
2+
- Fixes #413. Exclude deleted member functions.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`A8-4-7` - `InParametersForCheapToCopyTypesNotPassedByValue.ql`, `InParametersForNotCheapToCopyTypesNotPassedByReference.ql`:
2+
- Fixes #397. Exclude user defined operators and move constructors.`
3+
- Exclude parameters for instantiated templates because the declaration location of the function does not contain enough information about the type used in the instantiation to make an actionable alert.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A5-0-2` - `NonBooleanIfStmt.qll`, `NonBooleanIterationStmt.qll`:
2+
- Exclude compiler generated conditions.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`
2+
- Fix FP reported in #372. Exclude compiler generated variables.

cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ where
3636
else cond = " is used for an object"
3737
) and
3838
not exists(LambdaExpression lc | lc.getACapture().getField() = v) and
39-
not v.isFromUninstantiatedTemplate(_)
39+
not v.isFromUninstantiatedTemplate(_) and
40+
not v.isCompilerGenerated()
4041
select v, "Non-constant variable " + v.getName() + cond + " and is not modified."

cpp/autosar/src/rules/A8-4-7/InParametersForCheapToCopyTypesNotPassedByValue.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import cpp
1717
import codingstandards.cpp.autosar
1818
import TriviallySmallType
1919
import codingstandards.cpp.CommonTypes as CommonTypes
20+
import codingstandards.cpp.Class
2021

2122
/*
2223
* For the purposes of this rule, "cheap to copy" is defined as a trivially copyable type that is no
@@ -34,8 +35,10 @@ where
3435
) and
3536
t.isConst() and
3637
not exists(CatchBlock cb | cb.getParameter() = v) and
37-
not exists(CopyConstructor cc | cc.getAParameter() = v) and
38-
not v.isFromUninstantiatedTemplate(_)
38+
not exists(SpecialMemberFunction cc | cc.getAParameter() = v) and
39+
not exists(Operator op | op.getAParameter() = v) and
40+
not v.isFromUninstantiatedTemplate(_) and
41+
not v.isFromTemplateInstantiation(_)
3942
select v,
40-
"Parameter " + v.getName() + " is the trivially copyable type " + t.getName() +
41-
" but it is passed by reference instead of by value."
43+
"Parameter '" + v.getName() + "' is the trivially copyable type '" + t.getName() +
44+
"' but it is passed by reference instead of by value."

cpp/autosar/src/rules/A8-4-7/InParametersForNotCheapToCopyTypesNotPassedByReference.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ where
3131
not v.getType() instanceof TriviallySmallType and
3232
not v.getType().getUnderlyingType() instanceof ReferenceType and
3333
not exists(CatchBlock cb | cb.getParameter() = v) and
34-
not v.isFromUninstantiatedTemplate(_)
34+
not v.isFromUninstantiatedTemplate(_) and
35+
not v.isFromTemplateInstantiation(_)
3536
select v,
3637
"Parameter " + v.getName() +
3738
" is the trivially non-copyable type $@ but it is passed by value instead of by reference.",

cpp/autosar/src/rules/M9-3-3/MemberFunctionConstIfPossible.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ where
121121
not f.callsNonConstOwnMember() and
122122
not f.callsNonConstFromMemberVariable() and
123123
not f.isOverride() and
124-
not f.isFinal()
124+
not f.isFinal() and
125+
not f.isDeleted()
125126
select f, "Member function can be declared as const."

cpp/autosar/src/rules/M9-3-3/MemberFunctionStaticIfPossible.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ from NonStaticMemberFunction nonstatic
3939
where
4040
not isExcluded(nonstatic, ConstPackage::memberFunctionStaticIfPossibleQuery()) and
4141
not exists(ThisExpr t | t.getEnclosingFunction() = nonstatic) and
42-
not nonstatic.isVirtual()
42+
not nonstatic.isVirtual() and
43+
not nonstatic.isDeleted()
4344
select nonstatic, "Member function can be declared as static."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.cpp:20:19:20:21 | f5a | Parameter f5a is the trivially copyable type const S1 but it is passed by reference instead of by value. |
1+
| test.cpp:20:19:20:21 | f5a | Parameter 'f5a' is the trivially copyable type 'const S1' but it is passed by reference instead of by value. |

cpp/autosar/test/rules/A8-4-7/test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ inline S1 Value(size_t n, const char *data) {} // COMPLIANT
3737
struct A {
3838
int n;
3939
A(const A &a) : n(a.n) {} // COMPLIANT user-defined copy ctor
40+
A(const A &&other_a); // COMPLIANT user-defined move ctor
4041
};
42+
43+
class C1 {};
44+
45+
class C2 : public C1 {
46+
public:
47+
C2 &operator=(const C2 &); // COMPLIANT
48+
};

cpp/autosar/test/rules/M9-3-3/test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ class Z22 : Z1 {
161161
void f2() final {} // COMPLIANT
162162
void f3() { this->a = 100; } // COMPLIANT
163163
};
164+
165+
class Z3 {
166+
void f(int) = delete; // COMPLIANT
167+
};

cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ query predicate problems(Expr condition, string message) {
1414
not isExcluded(condition, getQuery()) and
1515
exists(IfStmt ifStmt, Type explicitConversionType |
1616
condition = ifStmt.getCondition() and
17+
//exclude any generated conditions
18+
not condition.isCompilerGenerated() and
1719
not ifStmt.isFromUninstantiatedTemplate(_) and
1820
explicitConversionType = condition.getExplicitlyConverted().getUnderlyingType() and
1921
not explicitConversionType instanceof BoolType and

cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ query predicate problems(Loop loopStmt, string message) {
1616
condition = loopStmt.getCondition() and
1717
explicitConversionType = condition.getExplicitlyConverted().getType().getUnspecifiedType() and
1818
not explicitConversionType instanceof BoolType and
19+
//exclude any generated conditions
20+
not condition.isCompilerGenerated() and
1921
message = "Iteration condition has non boolean type " + explicitConversionType + "."
2022
)
2123
}

0 commit comments

Comments
 (0)