Skip to content

Commit bd1e151

Browse files
authored
Merge pull request #638 from knewbury01/knewbury01/fix-406
A13-3-1: exclude implicit copy/move ctors
2 parents 2de0fcb + 3521709 commit bd1e151

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

change_notes/2024-07-11-fix-fp-406.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`:
2+
- Fixes #406. Exclude detection of overloaded implicit copy/move constructors.

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

+9-21
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,13 @@ where
3232
// allow for overloading with different number of parameters, because there is no
3333
// confusion on what function will be called.
3434
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-
)
35+
//ignore implicit copy and move constructor overloads
36+
not (
37+
f.isCompilerGenerated() and
38+
(f instanceof CopyConstructor or f instanceof MoveConstructor)
39+
) and
40+
msg = "function with a forwarding reference parameter" and
41+
firstMsgSegment = " " and
42+
overloaded = c and
43+
overload = f
5644
select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
| test.cpp:24:6:24:7 | F1 | Function overloads a $@. | test.cpp:27:25:27:26 | F1 | function with a forwarding reference parameter |
22
| test.cpp:50:3:50:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter |
33
| 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

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ template <class T> void F1(T &&x) {} //
4040
class A {
4141
public:
4242
// COMPLIANT[FALSE_POSITIVE] - by exception, constrained to not match
43-
// copy/move ctors
43+
// explicit copy/move ctors
4444
template <
4545
typename T,
4646
std::enable_if_t<!std::is_same<
@@ -66,13 +66,14 @@ struct B {
6666
typename T,
6767
std::enable_if_t<!std::is_same<
6868
std::remove_cv_t<std::remove_reference_t<T>>, A>::value> * = nullptr>
69-
B(T &&value) {} // COMPLIANT[FALSE_POSITIVE] - by exception
69+
B(T &&value) {} // COMPLIANT - by exception
7070
};
7171

7272
int main() {}
7373

7474
class C {
7575
public:
7676
C() {}
77-
template <typename T> C(T &&) {} // NON_COMPLIANT
77+
template <typename T>
78+
C(T &&) {} // COMPLIANT - ignore overloads of implicit copy/move ctors
7879
};

0 commit comments

Comments
 (0)