Skip to content
2 changes: 2 additions & 0 deletions change_notes/2024-01-30-exclusion-a13-3-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`A13-3-1`: `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`
- Fixes #399. Exclude functions that have different number of parameters.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ class Candidate extends TemplateFunction {
}
}

from Candidate c, Function f
from Candidate c, Function f, Function overload, Function overloaded, string msg
where
not isExcluded(f,
OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and
not f.isDeleted() and
f = c.getAnOverload()
select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function"
f = c.getAnOverload() and
// 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 (
msg = "implicit constructor" and
overloaded = f and
overload = c
) else (
msg = "function" and
overloaded = c and
overload = f
)
select overload, "Function overloads a $@ with a forwarding reference parameter.", overloaded, msg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
| test.cpp:50:3:50:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function |
| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function |
| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function |
| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function |
| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function |
16 changes: 12 additions & 4 deletions cpp/autosar/test/rules/A13-3-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ A b(a);
void F1(int &) = delete; // COMPLIANT by exception

struct B {
template <typename T,
std::enable_if_t<!std::is_same<T, B>::value> * = nullptr>
B(T &&value) {}
template <
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 by exception
};

int main() {}
int main() {}

class C {
public:
C() {} // COMPLIANT by exception
template <typename T> C(T &&) {}
};