-
Notifications
You must be signed in to change notification settings - Fork 73
First draft of RULE-0-2-2 #1038
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // GENERATED FILE - DO NOT MODIFY | ||
| import codingstandards.cpp.rules.unusedparameter.UnusedParameter | ||
|
|
||
| class TestFileQuery extends UnusedParameterSharedQuery, TestQuery { } | ||
| module UnusedParameterTestConfig implements UnusedParameterSharedConfigSig { | ||
| Query getQuery() { result instanceof TestQuery } | ||
| } | ||
|
|
||
| import UnusedParameterShared<UnusedParameterTestConfig> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - `A0-1-4`, `RULE-2-7` - `UnusedParameter.ql`: | ||
| - Refactored to be able to share most logic between MISRA C, MISRA C++, and AUTOSAR. No visible change in behavior expected. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | test.cpp:2:14:2:14 | x | Unused parameter 'x' for function $@. | test.cpp:2:8:2:8 | b | A::b | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/A0-1-4/UnusedParameter.ql |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class A { | ||
| void b(int x) {} // NON_COMPLIANT | ||
|
|
||
| // This is specially excluded from A0-1-4, covered by a different rule, | ||
| // even though it's non compliant in the shared query. | ||
| virtual void d(int x, int y) {} // COMPLIANT | ||
| }; |
| 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 DeadCode8Query = TUnusedParameterMisraCppQuery() | ||
|
|
||
| predicate isDeadCode8QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `unusedParameterMisraCpp` query | ||
| DeadCode8Package::unusedParameterMisraCppQuery() and | ||
| queryId = | ||
| // `@id` for the `unusedParameterMisraCpp` query | ||
| "cpp/misra/unused-parameter-misra-cpp" and | ||
| ruleId = "RULE-0-2-2" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module DeadCode8Package { | ||
| Query unusedParameterMisraCppQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `unusedParameterMisraCpp` query | ||
| TQueryCPP(TDeadCode8PackageQuery(TUnusedParameterMisraCppQuery())) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| | test.cpp:8:22:8:22 | x | Unused parameter 'x' for function $@. | test.cpp:8:6:8:16 | test_unused | test_unused | | ||
| | test.cpp:16:14:16:14 | x | Unused parameter 'x' for function $@. | test.cpp:16:8:16:8 | b | A::b | | ||
| | test.cpp:35:14:35:14 | y | Unused parameter 'y' for function $@. | test.cpp:34:9:34:9 | operator() | lambda expression | | ||
| | test.cpp:21:22:21:22 | x | Unused parameter 'x' for function $@. | test.cpp:21:16:21:16 | d | A::d | | ||
| | test.cpp:21:29:21:29 | y | Unused parameter 'y' for function $@. | test.cpp:21:16:21:16 | d | A::d | | ||
| | test.cpp:38:14:38:14 | y | Unused parameter 'y' for function $@. | test.cpp:37:9:37:9 | operator() | lambda expression | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // GENERATED FILE - DO NOT MODIFY | ||
| import codingstandards.cpp.rules.unusedparameter.UnusedParameter | ||
|
|
||
| class TestFileQuery extends UnusedParameterSharedQuery, TestQuery { } | ||
| module UnusedParameterTestConfig implements UnusedParameterSharedConfigSig { | ||
| Query getQuery() { result instanceof TestQuery } | ||
| } | ||
|
|
||
| import UnusedParameterShared<UnusedParameterTestConfig> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,10 +12,13 @@ void test_unnamed( | |||||
| } | ||||||
|
|
||||||
| class A { | ||||||
| int a(int x) { return x; } // COMPLIANT | ||||||
| void b(int x) {} // NON_COMPLIANT | ||||||
| void c(int) {} // COMPLIANT | ||||||
| virtual void d(int x, int y) {} // virtual, not covered by this rule | ||||||
| int a(int x) { return x; } // COMPLIANT | ||||||
| void b(int x) {} // NON_COMPLIANT | ||||||
| void c(int) {} // COMPLIANT | ||||||
|
|
||||||
| // This is a violation of A0-1-4, but not a violation of Rule 0-0-2, so it's | ||||||
|
||||||
| // This is a violation of A0-1-4, but not a violation of Rule 0-0-2, so it's | |
| // This is a violation of A0-1-4, but not a violation of RULE-0-2-2, so it's |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| /** | ||||||
| * @id cpp/misra/unused-parameter-misra-cpp | ||||||
| * @name RULE-0-2-2: There shall be no unused named parameters in non-virtual functions | ||||||
|
||||||
| * @name RULE-0-2-2: There shall be no unused named parameters in non-virtual functions | |
| * @name RULE-0-2-2: There shall be no unused named parameters in functions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| | test.cpp:1:13:1:13 | x | Unused parameter 'x' for function $@. | test.cpp:1:6:1:7 | f0 | f0 | | ||
| | test.cpp:9:13:9:13 | x | Unused parameter 'x' for function $@. | test.cpp:9:6:9:7 | f4 | f4 | | ||
| | test.cpp:18:13:18:13 | y | Unused parameter 'y' for function $@. | test.cpp:18:6:18:7 | f7 | f7 | | ||
| | test.cpp:21:13:21:13 | y | Unused parameter 'y' for function $@. | test.cpp:21:6:21:7 | f8 | f8 | | ||
| | test.cpp:24:23:24:23 | x | Unused parameter 'x' for function $@. | test.cpp:24:16:24:17 | m0 | C1::m0 | | ||
| | test.cpp:36:15:36:15 | x | Unused parameter 'x' for function $@. | test.cpp:36:8:36:9 | m0 | C3::m0 | | ||
| | test.cpp:37:15:37:15 | x | Unused parameter 'x' for function $@. | test.cpp:37:8:37:9 | m1 | C3::m1 | | ||
| | test.cpp:38:15:38:15 | x | Unused parameter 'x' for function $@. | test.cpp:38:8:38:9 | m2 | C3::m2 | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-0-2-2/UnusedParameterMisraCpp.ql |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| void f0(int x) {} // NON_COMPLIANT | ||
| void f1(int x) { x; } // COMPLIANT | ||
| void f2(int) {} // COMPLIANT | ||
|
|
||
| void f3(int); | ||
| void f3(int) {} // COMPLIANT | ||
|
|
||
| void f4(int); | ||
| void f4(int x) {} // NON_COMPLIANT | ||
|
|
||
| void f5(int); | ||
| void f5(int x) { x; } // COMPLIANT | ||
|
|
||
| void f6(int x); | ||
| void f6(int) {} // COMPLIANT | ||
|
|
||
| void f7(int x); | ||
| void f7(int y) {} // NON_COMPLIANT | ||
|
|
||
| void f8(int i); | ||
| void f8(int y) {} // NON_COMPLIANT | ||
|
|
||
| class C1 { | ||
| virtual void m0(int x) {} // NON_COMPLIANT | ||
| virtual void m1(int) {} // COMPLIANT | ||
| virtual void m2([[maybe_unused]] int x) {} // COMPLIANT | ||
| }; | ||
|
|
||
| class C2 : C1 { | ||
| void m0(int) override {} // COMPLIANT | ||
| void m1(int) override {} // COMPLIANT | ||
| void m2(int) override {} // COMPLIANT | ||
| }; | ||
|
|
||
| class C3 : C1 { | ||
| void m0(int x) override {} // NON_COMPLIANT | ||
| void m1(int x) override {} // NON_COMPLIANT | ||
| void m2(int x) override {} // NON_COMPLIANT | ||
| }; | ||
|
|
||
| class C4 : C1 { | ||
| void m0([[maybe_unused]] int x) override {} // COMPLIANT | ||
| void m1([[maybe_unused]] int x) override {} // COMPLIANT | ||
| void m2([[maybe_unused]] int x) override {} // COMPLIANT | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "MISRA-C++-2023": { | ||
| "RULE-0-2-2": { | ||
| "properties": { | ||
| "enforcement": "decidable", | ||
| "obligation": "required" | ||
| }, | ||
| "queries": [ | ||
| { | ||
| "description": "Unused parameters can indicate a mistake when implementing the function.", | ||
| "kind": "problem", | ||
| "name": "There shall be no unused named parameters in non-virtual functions", | ||
|
||
| "precision": "very-high", | ||
| "severity": "warning", | ||
| "short_name": "UnusedParameterMisraCpp", | ||
| "tags": [ | ||
| "scope/single-translation-unit", | ||
| "readability", | ||
| "maintainability" | ||
| ], | ||
| "shared_implementation_short_name": "UnusedParameter" | ||
| } | ||
| ], | ||
| "title": "There shall be no unused named parameters in non-virtual functions." | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change note mentions only
A0-1-4andRULE-2-7, but this PR also adds a new query forRULE-0-2-2. According to the development handbook guidelines for change notes, the change note should list all queries that have been modified or added. Please addRULE-0-2-2to the list of affected rules in the change note.