Skip to content

Commit b100f21

Browse files
committed
A13-3-1: improve alert msg
1 parent 8706c3d commit b100f21

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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

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

24-
from Candidate c, Function f
24+
from Candidate c, Function f, Function overload, Function overloaded, string msg
2525
where
2626
not isExcluded(f,
2727
OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and
2828
not f.isDeleted() and
2929
f = c.getAnOverload() and
3030
// allow for overloading with different number of parameters, because there is no
3131
// confusion on what function will be called.
32-
f.getNumberOfParameters() = c.getNumberOfParameters()
33-
select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function"
32+
f.getNumberOfParameters() = c.getNumberOfParameters() and
33+
//build a dynamic select statement that guarantees to read that the overloading function is the explicit one
34+
if
35+
(f instanceof CopyConstructor or f instanceof MoveConstructor) and
36+
f.isCompilerGenerated()
37+
then (
38+
msg = "implicit constructor" and
39+
overloaded = f and
40+
overload = c
41+
) else (
42+
msg = "function" and
43+
overloaded = c and
44+
overload = f
45+
)
46+
select overload, "Function overloads a $@ with a forwarding reference parameter.", overloaded, msg

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ A b(a);
6161
void F1(int &) = delete; // COMPLIANT by exception
6262

6363
struct B {
64-
template <typename T,
65-
std::enable_if_t<!std::is_same<T, B>::value> * = nullptr>
66-
B(T &&value) {}
64+
template <
65+
typename T,
66+
std::enable_if_t<!std::is_same<
67+
std::remove_cv_t<std::remove_reference_t<T>>, A>::value> * = nullptr>
68+
B(T &&value) {} // COMPLIANT by exception
6769
};
6870

6971
int main() {}

0 commit comments

Comments
 (0)