Skip to content

Commit 2cf4b66

Browse files
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Banned234
2 parents 113c464 + ad580d3 commit 2cf4b66

File tree

10 files changed

+149
-1
lines changed

10 files changed

+149
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Declarations1Query = TDeclarationsOfAFunctionSameParameterNameQuery()
7+
8+
predicate isDeclarations1QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `declarationsOfAFunctionSameParameterName` query
11+
Declarations1Package::declarationsOfAFunctionSameParameterNameQuery() and
12+
queryId =
13+
// `@id` for the `declarationsOfAFunctionSameParameterName` query
14+
"cpp/misra/declarations-of-a-function-same-parameter-name" and
15+
ruleId = "RULE-13-3-3" and
16+
category = "required"
17+
}
18+
19+
module Declarations1Package {
20+
Query declarationsOfAFunctionSameParameterNameQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `declarationsOfAFunctionSameParameterName` query
24+
TQueryCPP(TDeclarations1PackageQuery(TDeclarationsOfAFunctionSameParameterNameQuery()))
25+
}
26+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import DeadCode7
3030
import DeadCode8
3131
import DeadCode9
3232
import Declarations
33+
import Declarations1
3334
import ExceptionSafety
3435
import Exceptions1
3536
import Exceptions2
@@ -123,6 +124,7 @@ newtype TCPPQuery =
123124
TDeadCode8PackageQuery(DeadCode8Query q) or
124125
TDeadCode9PackageQuery(DeadCode9Query q) or
125126
TDeclarationsPackageQuery(DeclarationsQuery q) or
127+
TDeclarations1PackageQuery(Declarations1Query q) or
126128
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
127129
TExceptions1PackageQuery(Exceptions1Query q) or
128130
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -216,6 +218,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
216218
isDeadCode8QueryMetadata(query, queryId, ruleId, category) or
217219
isDeadCode9QueryMetadata(query, queryId, ruleId, category) or
218220
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
221+
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
219222
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
220223
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
221224
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @id cpp/misra/declarations-of-a-function-same-parameter-name
3+
* @name RULE-13-3-3: The parameters in all declarations or overrides of a function shall either be unnamed or have identical names
4+
* @description Parameters in some number of declarations or overrides of a function that do not
5+
* have identical names can lead to developer confusion.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-13-3-3
10+
* maintainability
11+
* readability
12+
* scope/system
13+
* external/misra/enforcement/decidable
14+
* external/misra/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.types.Compatible
20+
21+
predicate parameterNamesUnmatchedOverrides(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
22+
pragma[only_bind_into](f1).getFunction().(MemberFunction).getAnOverridingFunction+() =
23+
pragma[only_bind_into](f2).getFunction() and
24+
exists(string p1Name, string p2Name, int i |
25+
p1Name = f1.getParameterDeclarationEntry(i).getName() and
26+
p2Name = f2.getParameterDeclarationEntry(i).getName()
27+
|
28+
not p1Name = p2Name
29+
)
30+
}
31+
32+
from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, string case
33+
where
34+
not isExcluded(f1, Declarations1Package::declarationsOfAFunctionSameParameterNameQuery()) and
35+
not isExcluded(f2, Declarations1Package::declarationsOfAFunctionSameParameterNameQuery()) and
36+
not f1 = f2 and
37+
(
38+
f1.getDeclaration() = f2.getDeclaration() and
39+
parameterNamesUnmatched(f1, f2) and
40+
case = "re-declaration"
41+
or
42+
parameterNamesUnmatchedOverrides(f1, f2) and
43+
case = "override"
44+
)
45+
select f1, "The parameter names of " + case + " of $@ do not use the same names as declaration $@",
46+
f1, f1.getName(), f2, f2.getName()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| functions1.cpp:5:6:5:7 | declaration of f4 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions1.cpp:5:6:5:7 | declaration of f4 | f4 | functions2.cpp:6:6:6:7 | declaration of f4 | f4 |
2+
| functions1.cpp:6:6:6:7 | declaration of f5 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions1.cpp:6:6:6:7 | declaration of f5 | f5 | functions2.cpp:7:6:7:7 | declaration of f5 | f5 |
3+
| functions1.cpp:8:6:8:7 | definition of f6 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions1.cpp:8:6:8:7 | definition of f6 | f6 | functions2.cpp:9:13:9:14 | declaration of f6 | f6 |
4+
| functions1.cpp:21:16:21:22 | declaration of methodA | The parameter names of override of $@ do not use the same names as declaration $@ | functions1.cpp:21:16:21:22 | declaration of methodA | methodA | functions1.cpp:26:8:26:14 | declaration of methodA | methodA |
5+
| functions2.cpp:6:6:6:7 | declaration of f4 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions2.cpp:6:6:6:7 | declaration of f4 | f4 | functions1.cpp:5:6:5:7 | declaration of f4 | f4 |
6+
| functions2.cpp:7:6:7:7 | declaration of f5 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions2.cpp:7:6:7:7 | declaration of f5 | f5 | functions1.cpp:6:6:6:7 | declaration of f5 | f5 |
7+
| functions2.cpp:9:13:9:14 | declaration of f6 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions2.cpp:9:13:9:14 | declaration of f6 | f6 | functions1.cpp:8:6:8:7 | definition of f6 | f6 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.ql
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
void f1(int a); // COMPLIANT -- same name
2+
void f2(int a); // COMPLIANT -- unnamed is fine
3+
4+
void f3(int a); // COMPLIANT -- diff number but for those that exist, same
5+
void f4(int p, int b); // NON_COMPLIANT -- diff name
6+
void f5(int b, int a); // NON_COMPLIANT -- swapped names
7+
8+
void f6(int b, int a) { // NON_COMPLIANT
9+
return;
10+
}
11+
12+
void f7(int a) { // COMPLIANT
13+
return;
14+
}
15+
16+
template <class T> void f8(T t); // COMPLIANT
17+
template <>
18+
void f8<int>(int i); // COMPLIANT - specialization is a diff declaration
19+
20+
class ClassA {
21+
virtual void methodA(int i); // NON_COMPLIANT
22+
virtual void methodB(int i); // COMPLIANT
23+
};
24+
25+
class ClassB : ClassA {
26+
void methodA(int d) override;
27+
void methodB(int i) override;
28+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
void f1(int a); // COMPLIANT -- same name
2+
void f2(int); // COMPLIANT -- unnamed is fine
3+
4+
void f3(int a,
5+
int b); // COMPLIANT -- diff number but for those that exist, same
6+
void f4(int a, int b); // NON_COMPLIANT -- diff name
7+
void f5(int a, int b); // NON_COMPLIANT -- swapped names
8+
9+
extern void f6(int a, int b); // NON_COMPLIANT
10+
11+
extern void f7(int); // COMPLIANT

cpp/misra/test/rules/RULE-13-3-3/test.cpp

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"MISRA-C++-2023": {
3+
"RULE-13-3-3": {
4+
"properties": {
5+
"enforcement": "decidable",
6+
"obligation": "required"
7+
},
8+
"queries": [
9+
{
10+
"description": "Parameters in some number of declarations or overrides of a function that do not have identical names can lead to developer confusion.",
11+
"kind": "problem",
12+
"name": "The parameters in all declarations or overrides of a function shall either be unnamed or have identical names",
13+
"precision": "very-high",
14+
"severity": "error",
15+
"short_name": "DeclarationsOfAFunctionSameParameterName",
16+
"tags": [
17+
"maintainability",
18+
"readability",
19+
"scope/system"
20+
]
21+
}
22+
],
23+
"title": "The parameters in all declarations or overrides of a function shall either be unnamed or have identical names"
24+
}
25+
}
26+
}

rules.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ cpp,MISRA-C++-2023,RULE-13-1-1,Yes,Advisory,Decidable,Single Translation Unit,Cl
935935
cpp,MISRA-C++-2023,RULE-13-1-2,Yes,Required,Decidable,Single Translation Unit,An accessible base class shall not be both virtual and non-virtual in the same hierarchy,M10-1-3,ImportMisra23,Import,
936936
cpp,MISRA-C++-2023,RULE-13-3-1,Yes,Required,Decidable,Single Translation Unit,"User-declared member functions shall use the virtual, override and final specifiers appropriately",,Classes2,Easy,
937937
cpp,MISRA-C++-2023,RULE-13-3-2,Yes,Required,Decidable,Single Translation Unit,Parameters in an overriding virtual function shall not specify different default arguments,M8-3-1,ImportMisra23,Import,
938-
cpp,MISRA-C++-2023,RULE-13-3-3,Yes,Required,Decidable,System,The parameters in all declarations or overrides of a function shall either be unnamed or have identical names,RULE-8-3,Declarations2,Easy,
938+
cpp,MISRA-C++-2023,RULE-13-3-3,Yes,Required,Decidable,System,The parameters in all declarations or overrides of a function shall either be unnamed or have identical names,RULE-8-3,Declarations1,Easy,
939939
cpp,MISRA-C++-2023,RULE-13-3-4,Yes,Required,Decidable,Single Translation Unit,A comparison of a potentially virtual pointer to member function shall only be with nullptr,A5-10-1,ImportMisra23,Import,
940940
cpp,MISRA-C++-2023,RULE-14-1-1,Yes,Advisory,Decidable,Single Translation Unit,Non-static data members should be either all private or all public,,Classes2,Easy,
941941
cpp,MISRA-C++-2023,RULE-15-0-1,Yes,Required,Decidable,Single Translation Unit,Special member functions shall be provided appropriately,A12-0-1,Classes3,Medium,

0 commit comments

Comments
 (0)