Skip to content

Commit 443a8fb

Browse files
committed
C++: Test for DeclarationHidesVariable FP
1 parent 50e8034 commit 443a8fb

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
| hiding.cpp:6:17:6:17 | i | Variable i hides another variable of the same name (on $@). | hiding.cpp:4:13:4:13 | i | line 4 |
22
| hiding.cpp:18:15:18:15 | k | Variable k hides another variable of the same name (on $@). | hiding.cpp:15:11:15:11 | k | line 15 |
3+
| hiding.cpp:30:5:30:5 | (__begin) | Variable (__begin) hides another variable of the same name (on $@). | hiding.cpp:29:3:29:3 | (__begin) | line 29 |
4+
| hiding.cpp:30:5:30:5 | (__end) | Variable (__end) hides another variable of the same name (on $@). | hiding.cpp:29:3:29:3 | (__end) | line 29 |
5+
| hiding.cpp:30:5:30:5 | (__range) | Variable (__range) hides another variable of the same name (on $@). | hiding.cpp:29:3:29:3 | (__range) | line 29 |

cpp/ql/test/query-tests/Best Practices/Hiding/DeclarationHidesVariable/hiding.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ void f(void) {
33
if (1) {
44
int i;
55

6-
for(int i = 1; i < 10; i++) {
6+
for(int i = 1; i < 10; i++) { // BAD
77
;
88
}
99
}
@@ -15,7 +15,7 @@ namespace foo {
1515
int k;
1616
try {
1717
for (i = 0; i < 3; i++) {
18-
int k;
18+
int k; // BAD
1919
}
2020
}
2121
catch (int e) {
@@ -24,4 +24,9 @@ namespace foo {
2424
}
2525
}
2626

27-
27+
void nestedRangeBasedFor() {
28+
int xs[4], ys[4];
29+
for (auto x : xs)
30+
for (auto y : ys) // GOOD [FALSE POSITIVE]
31+
x = y = 0;
32+
}

0 commit comments

Comments
 (0)