Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
type = Variables::referenceArray;
else if (i->isArray())
type = (i->dimensions().size() == 1U) ? Variables::array : Variables::pointerArray;
else if (i->isReference())
else if (i->isReference() && !(i->valueType() && i->valueType()->type == ValueType::UNKNOWN_TYPE && Token::simpleMatch(i->typeStartToken(), "auto")))
type = Variables::reference;
else if (i->nameToken()->previous()->str() == "*" && i->nameToken()->strAt(-2) == "*")
type = Variables::pointerPointer;
Expand Down
11 changes: 11 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class TestUnusedVar : public TestFixture {
TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarDelete);
TEST_CASE(localvarLambda); // #8941, #8948
TEST_CASE(localvarStructuredBinding); // #10368

TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
Expand Down Expand Up @@ -5995,6 +5996,16 @@ class TestUnusedVar : public TestFixture {
ASSERT_EQUALS("", errout.str());
}


void localvarStructuredBinding() {
functionVariableUsage("void f() {\n" // #10368
" std::map<int, double> m;\n"
" m[2] = 2.0;\n"
" for (auto& [k, v] : m) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void localvarCppInitialization() {
functionVariableUsage("void foo() {\n"
" int buf[6];\n"
Expand Down