Skip to content

Commit 22c9fe0

Browse files
committed
DeadCode: Add MISRA C 2012 Rule 2.7
Adds a shared implementation query for identifying unused parameters.
1 parent 8bfb9c8 commit 22c9fe0

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.c:6:22:6:22 | x | Unused parameter 'x' for function $@. | test.c:6:6:6:16 | test_unused | test_unused |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.unusedparameter.UnusedParameter
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
4+
int test_used(int x) { return x; } // COMPLIANT
5+
6+
void test_unused(int x) {} // NON_COMPLIANT
7+
8+
void test_no_def(int x); // COMPLIANT - no definition, so cannot be "unused"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/unused-parameter
3+
* @name RULE-2-7: There should be no unused parameters in functions
4+
* @description Unused parameters can indicate a mistake when implementing the function.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity warning
8+
* @tags external/misra/id/rule-2-7
9+
* readability
10+
* maintainability
11+
* external/misra/obligation/advisory
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.unusedparameter.UnusedParameter
17+
18+
class UnusedParameterQuery extends UnusedParameterSharedQuery {
19+
UnusedParameterQuery() {
20+
this = DeadCodePackage::unusedParameterQuery()
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/unusedparameter/UnusedParameter.ql
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| test.cpp:3:22:3:22 | x | Unused parameter 'x' for function $@. | test.cpp:3:6:3:16 | test_unused | test_unused |
2-
| test.cpp:11:14:11:14 | x | Unused parameter 'x' for function $@. | test.cpp:11:8:11:8 | b | A::b |
1+
| test.cpp:6:22:6:22 | x | Unused parameter 'x' for function $@. | test.cpp:6:6:6:16 | test_unused | test_unused |
2+
| test.cpp:14:14:14:14 | x | Unused parameter 'x' for function $@. | test.cpp:14:8:14:8 | b | A::b |

cpp/common/test/rules/unusedparameter/test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// NOTICE: SOME OF THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
14
int test_used(int x) { return x; } // COMPLIANT
25

36
void test_unused(int x) {} // NON_COMPLIANT

0 commit comments

Comments
 (0)