Fix #10368 FP: unassignedVariable with structured binding (#3990)

This commit is contained in:
chrchr-github 2022-04-09 14:50:30 +02:00 committed by GitHub
parent 2bccde0e3b
commit 0636018df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

@ -217,6 +217,7 @@ private:
TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarDelete);
TEST_CASE(localvarLambda); // #8941, #8948
TEST_CASE(localvarStructuredBinding); // #10368
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
@ -5995,6 +5996,16 @@ private:
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"