Skip to content
2 changes: 1 addition & 1 deletion change_notes/2024-01-30-exclusion-a13-3-1.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
`A13-3-1`: `cpp/autosar/function-that-contains-forwarding-reference-as-its-argument-overloaded`
`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,12 +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() and
//allow for overloading with different number of parameters
f.getNumberOfParameters() = c.getNumberOfParameters()
select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function"
// 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
8 changes: 5 additions & 3 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,11 @@ 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() {}
Expand Down