@@ -709,6 +709,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
709709 else if (mTokenizer ->isC () ||
710710 i->typeEndToken ()->isStandardType () ||
711711 isRecordTypeWithoutSideEffects (i->type ()) ||
712+ mSettings ->library .detectContainer (i->typeStartToken (), /* iterator*/ false ) ||
712713 (i->isStlType () &&
713714 !Token::Match (i->typeStartToken ()->tokAt (2 ), " lock_guard|unique_lock|shared_ptr|unique_ptr|auto_ptr|shared_lock" )))
714715 type = Variables::standard;
@@ -728,7 +729,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
728729 break ;
729730 }
730731 }
731- if (i->isArray () && i->isClass ()) // Array of class/struct members. Initialized by ctor.
732+ if (i->isArray () && i->isClass () && // Array of class/struct members. Initialized by ctor except for std::array
733+ !(i->isStlType () && i->valueType () && i->valueType ()->containerTypeToken && i->valueType ()->containerTypeToken ->isStandardType ()))
732734 variables.write (i->declarationId (), i->nameToken ());
733735 if (i->isArray () && Token::Match (i->nameToken (), " %name% [ %var% ]" )) // Array index variable read.
734736 variables.read (i->nameToken ()->tokAt (2 )->varId (), i->nameToken ());
@@ -1176,7 +1178,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
11761178 }
11771179 // not assignment/initialization/increment => continue
11781180 const bool isAssignment = tok->isAssignmentOp () && tok->astOperand1 ();
1179- const bool isInitialization = (Token::Match (tok, " %var% (" ) && tok->variable () && tok->variable ()->nameToken () == tok);
1181+ const bool isInitialization = (Token::Match (tok, " %var% (|{ " ) && tok->variable () && tok->variable ()->nameToken () == tok);
11801182 const bool isIncrementOrDecrement = (tok->tokType () == Token::Type::eIncDecOp);
11811183 if (!isAssignment && !isInitialization && !isIncrementOrDecrement)
11821184 continue ;
0 commit comments