-
Notifications
You must be signed in to change notification settings - Fork 77
Add Declarations1 #1089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MichaelRFairhurst
merged 5 commits into
github:main
from
knewbury01:knewbury01/misracpp2023-declarations1
Mar 23, 2026
Merged
Add Declarations1 #1089
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f739b65
Add RULE-13-3-3
knewbury01 f999e10
Fix testcase labelling RULE-13-3-3
knewbury01 c6997fd
Address review comment
knewbury01 a4ca148
Apply a few other review comments
knewbury01 1371769
Merge branch 'main' into knewbury01/misracpp2023-declarations1
knewbury01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations1.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
cpp/misra/src/rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * @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 | ||
| f1.getFunction().(MemberFunction).getAnOverridingFunction*() = f2.getFunction() and | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| parameterNamesUnmatchedOverrides(f1, f2) and | ||
| case = "override" | ||
| ) | ||
| select f1, | ||
| "The parameter names of " + case + " of $@ do" + " not use the same names as declaration $@", f1, | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| f1.getName(), f2, f2.getName() | ||
7 changes: 7 additions & 0 deletions
7
cpp/misra/test/rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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:16:6:16:7 | definition of f7 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions1.cpp:16:6:16:7 | definition of f7 | f7 | functions2.cpp:15:13:15:14 | declaration of f7 | f7 | | ||
| | functions1.cpp:29:16:29:22 | declaration of methodA | The parameter names of override of $@ do not use the same names as declaration $@ | functions1.cpp:29:16:29:22 | declaration of methodA | methodA | functions1.cpp:34:8:34: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:15:13:15:14 | declaration of f7 | The parameter names of re-declaration of $@ do not use the same names as declaration $@ | functions2.cpp:15:13:15:14 | declaration of f7 | f7 | functions1.cpp:16:6:16:7 | definition of f7 | f7 | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-13-3-3/DeclarationsOfAFunctionSameParameterName.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| void f1(int a); // COMPLIANT -- same name | ||
| void f2(int a); // COMPLIANT -- unnamed is fine | ||
MichaelRFairhurst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
|
|
||
| typedef int wi; | ||
| typedef int hi; | ||
| typedef long a; | ||
|
|
||
| a f6(wi w, wi h) { // NON_COMPLIANT | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return (a)w * h; | ||
| } | ||
|
|
||
| void f7(int b, int a) { // NON_COMPLIANT | ||
| return; | ||
| } | ||
|
|
||
| void f8(int a) { // COMPLIANT | ||
| return; | ||
| } | ||
|
|
||
| template <class T> void f9(T t); // COMPLIANT | ||
| template <> | ||
| void f9<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; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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 | ||
|
|
||
| typedef int wi; | ||
| typedef int hi; | ||
| typedef long a; | ||
|
|
||
| extern a f6(wi w, hi h); // NON_COMPLIANT | ||
|
|
||
| extern void f7(int a, int b); // NON_COMPLIANT | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| extern void f8(int); // COMPLIANT | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.