@@ -1060,35 +1060,36 @@ void CheckUninitVar::checkScope(const Scope* scope)
10601060 if ((_tokenizer->isCPP () && i->type () && !i->isPointer () && i->type ()->needInitialization != Type::True) ||
10611061 i->isStatic () || i->isExtern () || i->isConst () || i->isArray () || i->isReference ())
10621062 continue ;
1063+
10631064 // don't warn for try/catch exception variable
1064- {
1065- const Token *start = i->typeStartToken ();
1066- while (start && start->isName ())
1067- start = start->previous ();
1068- if (start && Token::simpleMatch (start->previous (), " catch (" ))
1069- continue ;
1070- }
1065+ if (i->isThrow ())
1066+ continue ;
1067+
10711068 if (i->nameToken ()->strAt (1 ) == " (" || i->nameToken ()->strAt (1 ) == " {" )
10721069 continue ;
1070+
1071+ if (Token::Match (i->nameToken (), " %var% =" )) { // Variable is initialized, but Rhs might be not
1072+ checkRhs (i->nameToken (), *i, false , " " );
1073+ continue ;
1074+ }
1075+
10731076 bool stdtype = _tokenizer->isC ();
10741077 const Token* tok = i->typeStartToken ();
10751078 for (; tok && tok->str () != " ;" && tok->str () != " <" ; tok = tok->next ()) {
10761079 if (tok->isStandardType ())
10771080 stdtype = true ;
10781081 }
1082+
10791083 while (tok && tok->str () != " ;" )
10801084 tok = tok->next ();
10811085 if (!tok)
10821086 continue ;
1083- if (Token::Match (i->nameToken (), " %var% =" )) {
1084- checkRhs (i->nameToken (), *i, false , " " );
1085- continue ;
1086- }
1087+
10871088 if (stdtype || i->isPointer ()) {
10881089 bool alloc = false ;
10891090 checkScopeForVariable (scope, tok, *i, nullptr , nullptr , &alloc, " " );
10901091 }
1091- if (Token::Match ( i->typeStartToken (), " struct % type% *| %var% ; " ))
1092+ if (i->type ( ))
10921093 checkStruct (scope, tok, *i);
10931094 }
10941095
0 commit comments