File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1198,6 +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
12011202
12021203 for (const Token *tok = scope->bodyStart ; tok != scope->bodyEnd ; tok = tok->next ()) {
12031204 if (nextStructuredBindingTok) {
@@ -1366,8 +1367,10 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13661367 if (!expr->variable () || !expr->variable ()->isMaybeUnused ()) {
13671368 if (structuredBindingTokCount > 0 )
13681369 unusedStructuredBindingTokens.emplace_back (tok, expr);
1369- else
1370+ else {
13701371 unreadVariableError (tok, expr->expressionString (), false );
1372+ diagVars.emplace (expr->variable ());
1373+ }
13711374 }
13721375 }
13731376 }
@@ -1384,6 +1387,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13841387 ++it) {
13851388 const Variables::VariableUsage &usage = it->second ;
13861389
1390+ if (diagVars.find (usage._var ) != diagVars.end ())
1391+ continue ;
1392+
13871393 // variable has been marked as unused so ignore it
13881394 if (usage._var ->nameToken ()->isAttributeUnused () || usage._var ->nameToken ()->isAttributeUsed ())
13891395 continue ;
You can’t perform that action at this time.
0 commit comments