Skip to content

Commit 62f560f

Browse files
authored
Merge branch 'main' into rvermeulen/fix-issue-#311
2 parents e826932 + 0a23725 commit 62f560f

4 files changed

+52
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`:
2+
- Fixes #399. Exclude functions that have different number of parameters.

cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,36 @@ class Candidate extends TemplateFunction {
2121
}
2222
}
2323

24-
from Candidate c, Function f
24+
from
25+
Candidate c, Function f, Function overload, Function overloaded, string msg,
26+
string firstMsgSegment
2527
where
2628
not isExcluded(f,
2729
OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and
2830
not f.isDeleted() and
29-
f = c.getAnOverload()
30-
select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function"
31+
f = c.getAnOverload() and
32+
// allow for overloading with different number of parameters, because there is no
33+
// confusion on what function will be called.
34+
f.getNumberOfParameters() = c.getNumberOfParameters() and
35+
//build a dynamic select statement that guarantees to read that the overloading function is the explicit one
36+
if
37+
(f instanceof CopyConstructor or f instanceof MoveConstructor) and
38+
f.isCompilerGenerated()
39+
then (
40+
(
41+
f instanceof CopyConstructor and
42+
msg = "implicit copy constructor"
43+
or
44+
f instanceof MoveConstructor and
45+
msg = "implicit move constructor"
46+
) and
47+
firstMsgSegment = " with a forwarding reference parameter " and
48+
overloaded = f and
49+
overload = c
50+
) else (
51+
msg = "function with a forwarding reference parameter" and
52+
firstMsgSegment = " " and
53+
overloaded = c and
54+
overload = f
55+
)
56+
select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
| test.cpp:24:6:24:7 | F1 | Function overloads a $@ with a forwarding reference parameter. | test.cpp:27:25:27:26 | F1 | function |
2-
| test.cpp:49:3:49:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function |
3-
| test.cpp:50:3:50:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function |
4-
| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function |
5-
| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function |
1+
| test.cpp:24:6:24:7 | F1 | Function overloads a $@. | test.cpp:27:25:27:26 | F1 | function with a forwarding reference parameter |
2+
| test.cpp:50:3:50:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter |
3+
| test.cpp:51:3:51:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter |
4+
| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit copy constructor |
5+
| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit move constructor |
6+
| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit copy constructor |
7+
| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit move constructor |

cpp/autosar/test/rules/A13-3-1/test.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ template <class T> void F1(T &&x) {} //
3939

4040
class A {
4141
public:
42-
// COMPLIANT by exception, constrained to not match copy/move ctors
42+
// COMPLIANT[FALSE_POSITIVE] - by exception, constrained to not match
43+
// copy/move ctors
4344
template <
4445
typename T,
4546
std::enable_if_t<!std::is_same<
@@ -61,9 +62,17 @@ A b(a);
6162
void F1(int &) = delete; // COMPLIANT by exception
6263

6364
struct B {
64-
template <typename T,
65-
std::enable_if_t<!std::is_same<T, B>::value> * = nullptr>
66-
B(T &&value) {}
65+
template <
66+
typename T,
67+
std::enable_if_t<!std::is_same<
68+
std::remove_cv_t<std::remove_reference_t<T>>, A>::value> * = nullptr>
69+
B(T &&value) {} // COMPLIANT[FALSE_POSITIVE] - by exception
6770
};
6871

69-
int main() {}
72+
int main() {}
73+
74+
class C {
75+
public:
76+
C() {}
77+
template <typename T> C(T &&) {} // NON_COMPLIANT
78+
};

0 commit comments

Comments
 (0)