Skip to content

Commit 8d3cb78

Browse files
committed
C++: Fix DeclarationHidesVariable FP
We don't want alerts about the compiler-generated variables that appear in the desugaring of range-based `for`.
1 parent 443a8fb commit 8d3cb78

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

cpp/ql/src/Best Practices/Hiding/DeclarationHidesVariable.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Best_Practices.Hiding.Shadowing
1515
from LocalVariable lv1, LocalVariable lv2
1616
where
1717
shadowing(lv1, lv2) and
18+
not lv1.isCompilerGenerated() and
19+
not lv2.isCompilerGenerated() and
1820
not lv1.getParentScope().(Block).isInMacroExpansion() and
1921
not lv2.getParentScope().(Block).isInMacroExpansion()
2022
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ namespace foo {
2727
void nestedRangeBasedFor() {
2828
int xs[4], ys[4];
2929
for (auto x : xs)
30-
for (auto y : ys) // GOOD [FALSE POSITIVE]
30+
for (auto y : ys) // GOOD
3131
x = y = 0;
3232
}

0 commit comments

Comments
 (0)