mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
Merge pull request #1557 from jbj/hiding-range-based-for
C++: Fix DeclarationHidesVariable FP for nested range-based for loops
This commit is contained in:
@@ -15,6 +15,8 @@ import Best_Practices.Hiding.Shadowing
|
||||
from LocalVariable lv1, LocalVariable lv2
|
||||
where
|
||||
shadowing(lv1, lv2) and
|
||||
not lv1.isCompilerGenerated() and
|
||||
not lv2.isCompilerGenerated() and
|
||||
not lv1.getParentScope().(Block).isInMacroExpansion() and
|
||||
not lv2.getParentScope().(Block).isInMacroExpansion()
|
||||
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
|
||||
|
||||
@@ -3,7 +3,7 @@ void f(void) {
|
||||
if (1) {
|
||||
int i;
|
||||
|
||||
for(int i = 1; i < 10; i++) {
|
||||
for(int i = 1; i < 10; i++) { // BAD
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace foo {
|
||||
int k;
|
||||
try {
|
||||
for (i = 0; i < 3; i++) {
|
||||
int k;
|
||||
int k; // BAD
|
||||
}
|
||||
}
|
||||
catch (int e) {
|
||||
@@ -24,4 +24,9 @@ namespace foo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nestedRangeBasedFor() {
|
||||
int xs[4], ys[4];
|
||||
for (auto x : xs)
|
||||
for (auto y : ys) // GOOD
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user