Fixed #5347 (False positive: uninitialized variable (try catch))

This commit is contained in:
Daniel Marjamäki 2014-01-14 06:24:09 +01:00
parent d679a4c1f7
commit e45a2e2c61
2 changed files with 15 additions and 2 deletions

View File

@ -1072,8 +1072,13 @@ void CheckUninitVar::checkScope(const Scope* scope)
i->isStatic() || i->isExtern() || i->isConst() || i->isArray() || i->isReference())
continue;
// don't warn for try/catch exception variable
if (Token::Match(i->typeStartToken()->tokAt(-2), "catch ("))
continue;
{
const Token *start = i->typeStartToken();
while (start && start->isName())
start = start->previous();
if (start && Token::simpleMatch(start->previous(), "catch ("))
continue;
}
if (i->nameToken()->strAt(1) == "(")
continue;
bool stdtype = _tokenizer->isC();

View File

@ -2328,6 +2328,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n" // #5347
" try {\n"
" } catch (const char* e) {\n"
" A a = e;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// exit
checkUninitVar2("void f() {\n"
" int x;\n"