Uninitialized variables: Don't warn about try/catch exception variables

This commit is contained in:
Daniel Marjamäki 2013-12-24 07:39:15 +01:00
parent 042d3afb80
commit 753559fff3
2 changed files with 13 additions and 0 deletions

View File

@ -1071,6 +1071,9 @@ void CheckUninitVar::checkScope(const Scope* scope)
if ((_tokenizer->isCPP() && i->type() && !i->isPointer() && i->type()->needInitialization != Type::True) ||
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;
if (i->nameToken()->strAt(1) == "(")
continue;
bool stdtype = _tokenizer->isC();

View File

@ -2318,6 +2318,16 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
// try/catch : don't warn about exception variable
checkUninitVar2("void f() {\n"
" try {\n"
" } catch (CException* e) {\n"
" trace();\n"
" e->Delete();\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// exit
checkUninitVar2("void f() {\n"
" int x;\n"