From 753559fff361e50f7de19f54c6b81d68609daf90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Dec 2013 07:39:15 +0100 Subject: [PATCH] Uninitialized variables: Don't warn about try/catch exception variables --- lib/checkuninitvar.cpp | 3 +++ test/testuninitvar.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 4726cccd5..c9ab4ee37 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 6456923c7..a9301975c 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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"