Skip to content

Commit 5a54165

Browse files
authored
Merge pull request #498 from knewbury01/knewbury01/A8-4-7-fp
A8-4-7: exclude user defined operators and move constructors
2 parents ebad698 + f220399 commit 5a54165

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed
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.

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.",
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+
};

0 commit comments

Comments
 (0)