@@ -1198,7 +1198,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
11981198 const Token *nextStructuredBindingTok = nullptr ;
11991199 std::vector<std::pair<const Token*, const Token*>> unusedStructuredBindingTokens;
12001200 size_t structuredBindingTokCount = 0 ;
1201- std::set<const Variable*> diagVars ; // prevent duplicate warnings
1201+ std::set<const Variable*> diagUnreadVariable ; // prevent duplicate warnings
12021202
12031203 for (const Token *tok = scope->bodyStart ; tok != scope->bodyEnd ; tok = tok->next ()) {
12041204 if (nextStructuredBindingTok) {
@@ -1369,7 +1369,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13691369 unusedStructuredBindingTokens.emplace_back (tok, expr);
13701370 else {
13711371 unreadVariableError (tok, expr->expressionString (), false );
1372- diagVars .emplace (expr->variable ());
1372+ diagUnreadVariable .emplace (expr->variable ());
13731373 }
13741374 }
13751375 }
@@ -1387,9 +1387,6 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13871387 ++it) {
13881388 const Variables::VariableUsage &usage = it->second ;
13891389
1390- if (diagVars.find (usage._var ) != diagVars.end ())
1391- continue ;
1392-
13931390 // variable has been marked as unused so ignore it
13941391 if (usage._var ->nameToken ()->isAttributeUnused () || usage._var ->nameToken ()->isAttributeUsed ())
13951392 continue ;
@@ -1426,7 +1423,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
14261423 !(var->valueType () && var->valueType ()->container ) &&
14271424 !(var->isStatic () && isReturnedByRef (var, scope->function )))
14281425 unassignedVariableError (usage._var ->nameToken (), varname);
1429- else if (!usage._var ->isMaybeUnused () && !usage._modified && !usage._read && var) {
1426+ else if (!usage._var ->isMaybeUnused () && !usage._modified && !usage._read && var && diagUnreadVariable. find (usage. _var ) == diagUnreadVariable. end () ) {
14301427 const Token* vnt = var->nameToken ();
14311428 bool error = false ;
14321429 if (vnt->next ()->isSplittedVarDeclEq () || (!var->isReference () && vnt->strAt (1 ) == " =" )) {
0 commit comments