Fixed #5347 (False positive: uninitialized variable (try catch))
This commit is contained in:
parent
d679a4c1f7
commit
e45a2e2c61
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue