Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A13-3-1: exclude implicit copy/move ctors #638

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2024-07-11-fix-fp-406.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`:
- Fixes #406. Exclude detection of overloaded implicit copy/move constructors.
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,13 @@ where
// allow for overloading with different number of parameters, because there is no
// confusion on what function will be called.
f.getNumberOfParameters() = c.getNumberOfParameters() and
//build a dynamic select statement that guarantees to read that the overloading function is the explicit one
if
(f instanceof CopyConstructor or f instanceof MoveConstructor) and
f.isCompilerGenerated()
then (
(
f instanceof CopyConstructor and
msg = "implicit copy constructor"
or
f instanceof MoveConstructor and
msg = "implicit move constructor"
) and
firstMsgSegment = " with a forwarding reference parameter " and
overloaded = f and
overload = c
) else (
msg = "function with a forwarding reference parameter" and
firstMsgSegment = " " and
overloaded = c and
overload = f
)
//ignore implicit copy and move constructor overloads
not (
f.isCompilerGenerated() and
(f instanceof CopyConstructor or f instanceof MoveConstructor)
) and
msg = "function with a forwarding reference parameter" and
firstMsgSegment = " " and
overloaded = c and
overload = f
select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
| test.cpp:24:6:24:7 | F1 | Function overloads a $@. | test.cpp:27:25:27:26 | F1 | function with a forwarding reference parameter |
| test.cpp:50:3:50:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter |
| test.cpp:51:3:51:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter |
| 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 |
| 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 |
| 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 |
| 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 |
7 changes: 4 additions & 3 deletions cpp/autosar/test/rules/A13-3-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <class T> void F1(T &&x) {} //
class A {
public:
// COMPLIANT[FALSE_POSITIVE] - by exception, constrained to not match
// copy/move ctors
// explicit copy/move ctors
template <
typename T,
std::enable_if_t<!std::is_same<
Expand All @@ -66,13 +66,14 @@ struct B {
typename T,
std::enable_if_t<!std::is_same<
std::remove_cv_t<std::remove_reference_t<T>>, A>::value> * = nullptr>
B(T &&value) {} // COMPLIANT[FALSE_POSITIVE] - by exception
B(T &&value) {} // COMPLIANT - by exception
};

int main() {}

class C {
public:
C() {}
template <typename T> C(T &&) {} // NON_COMPLIANT
template <typename T>
C(T &&) {} // COMPLIANT - ignore overloads of implicit copy/move ctors
};
Loading