Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b31915

Browse filesBrowse files
committed
DeadCode: Add MISRA Rule 2-1
Add MISRA Rule 2.1 as an import of the UnreachableCode query.
1 parent 62181ae commit 3b31915
Copy full SHA for 3b31915

File tree

Expand file treeCollapse file tree

7 files changed

+60
-3
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+60
-3
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.c:17:3:17:12 | declaration | This statement in function $@ is unreachable. | test.c:15:5:15:21 | test_after_return | test_after_return |
2+
| test.c:21:10:22:12 | { ... } | This statement in function $@ is unreachable. | test.c:20:5:20:27 | test_constant_condition | test_constant_condition |
+2Lines 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.unreachablecode.UnreachableCode
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND CHANGES
2+
// SHOULD BE REFLECTED THERE AS WELL.
3+
4+
void test_switch(int p1) {
5+
int l1 = 0;
6+
switch (p1) {
7+
l1 = p1; // NON_COMPLIANT[FALSE_NEGATIVE]
8+
case 1:
9+
break;
10+
default:
11+
break;
12+
}
13+
}
14+
15+
int test_after_return() {
16+
return 0;
17+
int l1 = 0; // NON_COMPLIANT - function has returned by this point
18+
}
19+
20+
int test_constant_condition() {
21+
if (0) { // NON_COMPLIANT
22+
return 1;
23+
} else { // COMPLIANT
24+
return 2;
25+
}
26+
}
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id c/misra/unreachable-code
3+
* @name RULE-2-1: A project shall not contain unreachable code
4+
* @description Unreachable code complicates the program and can indicate a possible mistake on the
5+
* part of the programmer.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/misra/id/rule-2-1
10+
* readability
11+
* maintainability
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import codingstandards.cpp.rules.unreachablecode.UnreachableCode
18+
19+
class UnreachableCodeQuery extends UnreachableCodeSharedQuery {
20+
UnreachableCodeQuery() {
21+
this = DeadCodePackage::unreachableCodeQuery()
22+
}
23+
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/unreachablecode/UnreachableCode.ql
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
| test.cpp:14:3:14:12 | declaration | This statement in function $@ is unreachable. | test.cpp:12:5:12:21 | test_after_return | test_after_return |
22
| test.cpp:18:10:19:12 | { ... } | This statement in function $@ is unreachable. | test.cpp:17:5:17:27 | test_constant_condition | test_constant_condition |
3-
| test.cpp:26:10:27:12 | { ... } | This statement in function $@ is unreachable. | test.cpp:25:24:25:24 | f | f |
4-
| test.cpp:47:12:48:14 | { ... } | This statement in function $@ is unreachable. | test.cpp:46:7:46:8 | h1 | h1 |
5-
| test.cpp:52:12:53:14 | { ... } | This statement in function $@ is unreachable. | test.cpp:51:7:51:8 | h2 | h2 |
3+
| test.cpp:29:10:30:12 | { ... } | This statement in function $@ is unreachable. | test.cpp:28:24:28:24 | f | f |
4+
| test.cpp:50:12:51:14 | { ... } | This statement in function $@ is unreachable. | test.cpp:49:7:49:8 | h1 | h1 |
5+
| test.cpp:55:12:56:14 | { ... } | This statement in function $@ is unreachable. | test.cpp:54:7:54:8 | h2 | h2 |

‎cpp/common/test/rules/unreachablecode/test.cpp

Copy file name to clipboardExpand all lines: cpp/common/test/rules/unreachablecode/test.cpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ int test_constant_condition() {
2222
}
2323
}
2424

25+
// NOTICE: THE TEST CASES ABOVE ARE ALSO INCLUDED IN THE C TEST CASE AND CHANGES
26+
// SHOULD BE REFLECTED THERE AS WELL.
27+
2528
template <class T> int f() {
2629
if (0) { // NON_COMPLIANT - block is unreachable in all instances
2730
return 3;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.