File tree Expand file tree Collapse file tree 7 files changed +60
-3
lines changed
cpp/common/test/rules/unreachablecode
common/test/rules/unreachablecode Expand file tree Collapse file tree 7 files changed +60
-3
lines changed Original file line number Diff line number Diff line change
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 |
Original file line number Diff line number Diff line change
1
+ // GENERATED FILE - DO NOT MODIFY
2
+ import codingstandards.cpp.rules.unreachablecode.UnreachableCode
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ c/common/test/rules/unreachablecode/UnreachableCode.ql
Original file line number Diff line number Diff line change 1
1
| 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 |
2
2
| 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 |
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ int test_constant_condition() {
22
22
}
23
23
}
24
24
25
+ // NOTICE: THE TEST CASES ABOVE ARE ALSO INCLUDED IN THE C TEST CASE AND CHANGES
26
+ // SHOULD BE REFLECTED THERE AS WELL.
27
+
25
28
template <class T > int f () {
26
29
if (0 ) { // NON_COMPLIANT - block is unreachable in all instances
27
30
return 3 ;
You can’t perform that action at this time.
0 commit comments