@@ -885,15 +885,15 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, Alloc alloc
885885
886886bool CheckUninitVar::isVariableUsage (const Token *vartok, bool pointer, Alloc alloc) const
887887{
888- if (alloc == NO_ALLOC && ((Token::Match (vartok->previous (), " return|delete" ) && vartok-> strAt ( 1 ) != " = " ) || (vartok->strAt (-1 ) == " ]" && vartok->linkAt (-1 )->strAt (-1 ) == " delete" )))
888+ if (alloc == NO_ALLOC && ((Token::Match (vartok->previous (), " return|delete %var% !!= " ) ) || (vartok->strAt (-1 ) == " ]" && vartok->linkAt (-1 )->strAt (-1 ) == " delete" )))
889889 return true ;
890890
891891 // Passing variable to typeof/__alignof__
892892 if (Token::Match (vartok->tokAt (-3 ), " typeof|__alignof__ ( * %name%" ))
893893 return false ;
894894
895895 // Accessing Rvalue member using "." or "->"
896- if (vartok->strAt ( 1 ) == " . " && vartok-> strAt (- 1 ) != " & " ) {
896+ if (Token::Match ( vartok->previous (), " !!& %var% . " ) ) {
897897 // Is struct member passed to function?
898898 if (!pointer && Token::Match (vartok->previous (), " [,(] %name% . %name%" )) {
899899 // TODO: there are FN currently:
@@ -939,20 +939,21 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
939939 if (_tokenizer->isCPP () && alloc == ARRAY && Token::Match (vartok->tokAt (-4 ), " & %var% =|( *" ))
940940 return false ;
941941
942- if (_tokenizer->isCPP () && Token::Match (vartok->previous (), " >>|<<" )) {
942+ if (isLikelyStreamRead (_tokenizer->isCPP (), vartok->previous ()))
943+ return false ;
944+
945+ if (_tokenizer->isCPP () && Token::Match (vartok->previous (), " <<" )) {
943946 const Token* tok2 = vartok->previous ();
944- if (Token::simpleMatch (tok2->astOperand1 (), " >>" ))
945- return false ; // Looks like stream operator, initializes the variable
946- if (Token::simpleMatch (tok2, " <<" )) {
947- // Looks like stream operator, but could also initialize the variable. Check lhs.
948- do {
949- tok2 = tok2->astOperand1 ();
950- } while (Token::simpleMatch (tok2, " <<" ));
951- if (tok2 && tok2->strAt (-1 ) == " ::" )
952- tok2 = tok2->previous ();
953- if (tok2 && (Token::simpleMatch (tok2->previous (), " std ::" ) || (tok2->variable () && tok2->variable ()->isStlType ()) || tok2->isStandardType () || tok2->isEnumType ()))
954- return true ;
955- }
947+
948+ // Looks like stream operator, but could also initialize the variable. Check lhs.
949+ do {
950+ tok2 = tok2->astOperand1 ();
951+ } while (Token::simpleMatch (tok2, " <<" ));
952+ if (tok2 && tok2->strAt (-1 ) == " ::" )
953+ tok2 = tok2->previous ();
954+ if (tok2 && (Token::simpleMatch (tok2->previous (), " std ::" ) || (tok2->variable () && tok2->variable ()->isStlType ()) || tok2->isStandardType () || tok2->isEnumType ()))
955+ return true ;
956+
956957 const Variable *var = vartok->tokAt (-2 )->variable ();
957958 return (var && (var->typeStartToken ()->isStandardType () || var->typeStartToken ()->isEnumType ()));
958959 }
0 commit comments