Skip to content

Commit 9194af9

Browse files
committed
Do not report "Declaration hides variable" for unnamed variables
1 parent 10a94cf commit 9194af9

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where
1818
not lv1.isCompilerGenerated() and
1919
not lv2.isCompilerGenerated() and
2020
not lv1.getParentScope().(BlockStmt).isInMacroExpansion() and
21-
not lv2.getParentScope().(BlockStmt).isInMacroExpansion()
21+
not lv2.getParentScope().(BlockStmt).isInMacroExpansion() and
22+
not lv1.getName() = "(unnamed local variable)"
2223
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
2324
"line " + lv2.getLocation().getStartLine().toString()
Original file line numberDiff line numberDiff line change
@@ -1,4 +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: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 |
4-
| 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 |

cpp/ql/test/query-tests/Best Practices/Hiding/DeclarationHidesVariable/hiding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void structuredBinding() {
3535
int xs[1] = {1};
3636
auto [x] = xs;
3737
{
38-
auto [x] = xs; // BAD
39-
auto [y] = xs; // GOOD [FALSE POSITIVE]
38+
auto [x] = xs; // BAD [NOT DETECTED]
39+
auto [y] = xs; // GOOD
4040
}
4141
}

0 commit comments

Comments
 (0)