Uninitialized variables: Don't warn about try/catch exception variables
This commit is contained in:
parent
042d3afb80
commit
753559fff3
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue