forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql
More file actions
50 lines (47 loc) · 1.83 KB
/
FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql
File metadata and controls
50 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @id cpp/autosar/function-that-contains-forwarding-reference-as-its-argument-overloaded
* @name A13-3-1: A function that contains 'forwarding reference' as its argument shall not be overloaded
* @description A function that contains 'forwarding reference' as its argument shall not be
* overloaded.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/autosar/id/a13-3-1
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
class Candidate extends TemplateFunction {
Candidate() {
this.getAParameter().getType().(RValueReferenceType).getBaseType() instanceof TemplateParameter
}
}
from
Candidate c, Function f, Function overload, Function overloaded, string msg,
string firstMsgSegment
where
not isExcluded(f,
OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and
not f.isDeleted() and
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
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
)
select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg