Skip to content

Commit 1f8e2ba

Browse files
committed
Scope: Ensure loop entries have correct parent scope
All direct children of a for loop should have the for loop itself as the scope.
1 parent b8b4131 commit 1f8e2ba

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cpp/common/src/codingstandards/cpp/Scope.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Internal {
2929
* }
3030
*/
3131

32-
exists(Loop loop | loop.getStmt() = e and result = loop)
32+
exists(Loop loop | loop.getAChild() = e and result = loop)
3333
or
3434
exists(IfStmt ifStmt |
3535
(ifStmt.getThen() = e or ifStmt.getElse() = e) and
@@ -38,7 +38,7 @@ module Internal {
3838
or
3939
exists(SwitchStmt switchStmt | switchStmt.getStmt() = e and result = switchStmt)
4040
or
41-
not exists(Loop loop | loop.getStmt() = e) and
41+
not exists(Loop loop | loop.getAChild() = e) and
4242
not exists(IfStmt ifStmt | ifStmt.getThen() = e or ifStmt.getElse() = e) and
4343
not exists(SwitchStmt switchStmt | switchStmt.getStmt() = e) and
4444
if exists(e.getParentScope())

cpp/common/test/library/codingstandards/cpp/scope/ParentScope.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@
2626
| test.cpp:10:23:10:25 | id1 | test.cpp:10:8:10:17 | test_scope |
2727
| test.cpp:10:28:34:3 | { ... } | test.cpp:10:8:10:17 | test_scope |
2828
| test.cpp:11:5:33:5 | for(...;...;...) ... | test.cpp:10:28:34:3 | { ... } |
29-
| test.cpp:11:10:11:17 | declaration | test.cpp:10:28:34:3 | { ... } |
29+
| test.cpp:11:10:11:17 | declaration | test.cpp:11:5:33:5 | for(...;...;...) ... |
3030
| test.cpp:11:14:11:16 | id1 | test.cpp:11:5:33:5 | for(...;...;...) ... |
3131
| test.cpp:11:19:11:21 | id1 | test.cpp:10:28:34:3 | { ... } |
32-
| test.cpp:11:19:11:25 | ... < ... | test.cpp:10:28:34:3 | { ... } |
32+
| test.cpp:11:19:11:25 | ... < ... | test.cpp:11:5:33:5 | for(...;...;...) ... |
3333
| test.cpp:11:25:11:25 | 1 | test.cpp:10:28:34:3 | { ... } |
3434
| test.cpp:11:28:11:30 | id1 | test.cpp:10:28:34:3 | { ... } |
35-
| test.cpp:11:28:11:32 | ... ++ | test.cpp:10:28:34:3 | { ... } |
35+
| test.cpp:11:28:11:32 | ... ++ | test.cpp:11:5:33:5 | for(...;...;...) ... |
3636
| test.cpp:11:35:33:5 | { ... } | test.cpp:11:5:33:5 | for(...;...;...) ... |
3737
| test.cpp:12:7:32:7 | for(...;...;...) ... | test.cpp:11:35:33:5 | { ... } |
38-
| test.cpp:12:12:12:19 | declaration | test.cpp:11:35:33:5 | { ... } |
38+
| test.cpp:12:12:12:19 | declaration | test.cpp:12:7:32:7 | for(...;...;...) ... |
3939
| test.cpp:12:16:12:18 | id1 | test.cpp:12:7:32:7 | for(...;...;...) ... |
4040
| test.cpp:12:21:12:23 | id1 | test.cpp:11:35:33:5 | { ... } |
41-
| test.cpp:12:21:12:27 | ... < ... | test.cpp:11:35:33:5 | { ... } |
41+
| test.cpp:12:21:12:27 | ... < ... | test.cpp:12:7:32:7 | for(...;...;...) ... |
4242
| test.cpp:12:27:12:27 | 1 | test.cpp:11:35:33:5 | { ... } |
4343
| test.cpp:12:30:12:32 | id1 | test.cpp:11:35:33:5 | { ... } |
44-
| test.cpp:12:30:12:34 | ... ++ | test.cpp:11:35:33:5 | { ... } |
44+
| test.cpp:12:30:12:34 | ... ++ | test.cpp:12:7:32:7 | for(...;...;...) ... |
4545
| test.cpp:12:37:32:7 | { ... } | test.cpp:12:7:32:7 | for(...;...;...) ... |
4646
| test.cpp:13:9:31:9 | { ... } | test.cpp:12:37:32:7 | { ... } |
4747
| test.cpp:14:11:14:18 | declaration | test.cpp:13:9:31:9 | { ... } |

0 commit comments

Comments
 (0)