diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 0118c482e..de9430d5d 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 02eaf6af3..caf81ed82 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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 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"