C++: Fix DeclarationHidesVariable FP

We don't want alerts about the compiler-generated variables that appear
in the desugaring of range-based `for`.
This commit is contained in:
Jonas Jensen
2019-07-05 20:36:16 +02:00
parent 443a8fbc07
commit 8d3cb78a9d
3 changed files with 3 additions and 4 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

@@ -1,5 +1,2 @@
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |

View File

@@ -27,6 +27,6 @@ namespace foo {
void nestedRangeBasedFor() {
int xs[4], ys[4];
for (auto x : xs)
for (auto y : ys) // GOOD [FALSE POSITIVE]
for (auto y : ys) // GOOD
x = y = 0;
}