Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype Declarations1Query = TDeclarationsOfAFunctionSameParameterNameQuery()

predicate isDeclarations1QueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `declarationsOfAFunctionSameParameterName` query
Declarations1Package::declarationsOfAFunctionSameParameterNameQuery() and
queryId =
// `@id` for the `declarationsOfAFunctionSameParameterName` query
"cpp/misra/declarations-of-a-function-same-parameter-name" and
ruleId = "RULE-13-3-3" and
category = "required"
}

module Declarations1Package {
Query declarationsOfAFunctionSameParameterNameQuery() {
//autogenerate `Query` type
result =
// `Query` type for `declarationsOfAFunctionSameParameterName` query
TQueryCPP(TDeclarations1PackageQuery(TDeclarationsOfAFunctionSameParameterNameQuery()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DeadCode7
import DeadCode8
import DeadCode9
import Declarations
import Declarations1
import ExceptionSafety
import Exceptions1
import Exceptions2
Expand Down Expand Up @@ -117,6 +118,7 @@ newtype TCPPQuery =
TDeadCode8PackageQuery(DeadCode8Query q) or
TDeadCode9PackageQuery(DeadCode9Query q) or
TDeclarationsPackageQuery(DeclarationsQuery q) or
TDeclarations1PackageQuery(Declarations1Query q) or
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
TExceptions1PackageQuery(Exceptions1Query q) or
TExceptions2PackageQuery(Exceptions2Query q) or
Expand Down Expand Up @@ -207,6 +209,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isDeadCode8QueryMetadata(query, queryId, ruleId, category) or
isDeadCode9QueryMetadata(query, queryId, ruleId, category) or
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.ql
28 changes: 28 additions & 0 deletions cpp/misra/test/rules/RULE-13-3-3/functions1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
void f1(int a); // COMPLIANT -- same name
void f2(int a); // COMPLIANT -- unnamed is fine

void f3(int a); // COMPLIANT -- diff number but for those that exist, same
void f4(int p, int b); // NON_COMPLIANT -- diff name
void f5(int b, int a); // NON_COMPLIANT -- swapped names

void f6(int b, int a) { // NON_COMPLIANT
return;
}

void f7(int a) { // COMPLIANT
return;
}

template <class T> void f8(T t); // COMPLIANT
template <>
void f8<int>(int i); // COMPLIANT - specialization is a diff declaration

class ClassA {
virtual void methodA(int i); // NON_COMPLIANT
virtual void methodB(int i); // COMPLIANT
};

class ClassB : ClassA {
void methodA(int d) override;
void methodB(int i) override;
};
11 changes: 11 additions & 0 deletions cpp/misra/test/rules/RULE-13-3-3/functions2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
void f1(int a); // COMPLIANT -- same name
void f2(int); // COMPLIANT -- unnamed is fine

void f3(int a,
int b); // COMPLIANT -- diff number but for those that exist, same
void f4(int a, int b); // NON_COMPLIANT -- diff name
void f5(int a, int b); // NON_COMPLIANT -- swapped names

extern void f6(int a, int b); // NON_COMPLIANT

extern void f7(int); // COMPLIANT
Empty file.
26 changes: 26 additions & 0 deletions rule_packages/cpp/Declarations1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"MISRA-C++-2023": {
"RULE-13-3-3": {
"properties": {
"enforcement": "decidable",
"obligation": "required"
},
"queries": [
{
"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",
"name": "The parameters in all declarations or overrides of a function shall either be unnamed or have identical names",
"precision": "very-high",
"severity": "error",
"short_name": "DeclarationsOfAFunctionSameParameterName",
"tags": [
"maintainability",
"readability",
"scope/system"
]
}
],
"title": "The parameters in all declarations or overrides of a function shall either be unnamed or have identical names"
}
}
}
2 changes: 1 addition & 1 deletion rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ cpp,MISRA-C++-2023,RULE-13-1-1,Yes,Advisory,Decidable,Single Translation Unit,Cl
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,
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,
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,
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,
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,
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,
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,
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,
Expand Down
Loading