Merge pull request #7758 from jketema/unnamed-variable-fix

C++: Do not report "Declaration hides variable" for unnamed variables
This commit is contained in:
Mathias Vorreiter Pedersen
2022-01-26 15:36:04 +00:00
committed by GitHub
3 changed files with 16 additions and 2 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

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Fix an issue with the `cpp/declaration-hides-variable` query where it would report variables that are unnamed in a database.

View File

@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c++17
void f(void) {
if (1) {
int i;
@@ -30,3 +30,12 @@ void nestedRangeBasedFor() {
for (auto y : ys) // GOOD
x = y = 0;
}
void structuredBinding() {
int xs[1] = {1};
auto [x] = xs;
{
auto [x] = xs; // BAD [NOT DETECTED]
auto [y] = xs; // GOOD
}
}