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:
Robert Marsh
2019-07-05 14:56:02 -07:00
committed by GitHub
2 changed files with 10 additions and 3 deletions

View File

@@ -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,

View File

@@ -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;
}