Do not report "Declaration hides variable" for unnamed variables

This commit is contained in:
Jeroen Ketema
2022-01-26 15:10:37 +01:00
parent 10a94cfa45
commit 9194af9b15
3 changed files with 4 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ where
not lv1.isCompilerGenerated() and
not lv2.isCompilerGenerated() and
not lv1.getParentScope().(BlockStmt).isInMacroExpansion() and
not lv2.getParentScope().(BlockStmt).isInMacroExpansion()
not lv2.getParentScope().(BlockStmt).isInMacroExpansion() and
not lv1.getName() = "(unnamed local variable)"
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
"line " + lv2.getLocation().getStartLine().toString()

View File

@@ -1,4 +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:38:10:38:10 | (unnamed local variable) | Variable (unnamed local variable) hides another variable of the same name (on $@). | hiding.cpp:36:8:36:8 | (unnamed local variable) | line 36 |
| hiding.cpp:39:10:39:10 | (unnamed local variable) | Variable (unnamed local variable) hides another variable of the same name (on $@). | hiding.cpp:36:8:36:8 | (unnamed local variable) | line 36 |

View File

@@ -35,7 +35,7 @@ void structuredBinding() {
int xs[1] = {1};
auto [x] = xs;
{
auto [x] = xs; // BAD
auto [y] = xs; // GOOD [FALSE POSITIVE]
auto [x] = xs; // BAD [NOT DETECTED]
auto [y] = xs; // GOOD
}
}