forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeclarationsOfAFunctionSameParameterName.ql
More file actions
46 lines (43 loc) · 1.76 KB
/
DeclarationsOfAFunctionSameParameterName.ql
File metadata and controls
46 lines (43 loc) · 1.76 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
/**
* @id cpp/misra/declarations-of-a-function-same-parameter-name
* @name RULE-13-3-3: The parameters in all declarations or overrides of a function shall either be unnamed or have identical names
* @description Parameters in some number of declarations or overrides of a function that do not
* have identical names can lead to developer confusion.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-13-3-3
* maintainability
* readability
* scope/system
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import codingstandards.cpp.types.Compatible
predicate parameterNamesUnmatchedOverrides(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
pragma[only_bind_into](f1).getFunction().(MemberFunction).getAnOverridingFunction+() =
pragma[only_bind_into](f2).getFunction() and
exists(string p1Name, string p2Name, int i |
p1Name = f1.getParameterDeclarationEntry(i).getName() and
p2Name = f2.getParameterDeclarationEntry(i).getName()
|
not p1Name = p2Name
)
}
from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, string case
where
not isExcluded(f1, Declarations1Package::declarationsOfAFunctionSameParameterNameQuery()) and
not isExcluded(f2, Declarations1Package::declarationsOfAFunctionSameParameterNameQuery()) and
not f1 = f2 and
(
f1.getDeclaration() = f2.getDeclaration() and
parameterNamesUnmatched(f1, f2) and
case = "re-declaration"
or
parameterNamesUnmatchedOverrides(f1, f2) and
case = "override"
)
select f1, "The parameter names of " + case + " of $@ do not use the same names as declaration $@",
f1, f1.getName(), f2, f2.getName()