From 4d185f09359398a922260588935e1c2339632cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 11 Dec 2009 21:34:04 +0100 Subject: [PATCH] Fixed #1080 (false positive: member variable not initialized) --- lib/checkclass.cpp | 10 +++++++++- test/testclass.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 256b8ac03..2d2198018 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -241,12 +241,20 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va break; } - if (!Token::Match(ftok->next(), "%var%") && !Token::Match(ftok->next(), "this . %var%")) + if (!Token::Match(ftok->next(), "%var%") && + !Token::Match(ftok->next(), "this . %var%") && + !Token::Match(ftok->next(), "( * this ) . %var%")) continue; // Goto the first token in this statement.. ftok = ftok->next(); + // Skip "( * this )" + if (Token::simpleMatch(ftok, "( * this ) .")) + { + ftok = ftok->tokAt(5); + } + // Skip "this->" if (Token::simpleMatch(ftok, "this .")) ftok = ftok->tokAt(2); diff --git a/test/testclass.cpp b/test/testclass.cpp index 044f2ea47..d6deb08aa 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -45,6 +45,7 @@ private: TEST_CASE(virtualDestructorTemplate); TEST_CASE(uninitVar1); + TEST_CASE(uninitVar2); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -397,6 +398,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVar2() + { + checkUninitVar("class John\n" + "{\n" + "public:\n" + " John() { (*this).i = 0; }\n" + "private:\n" + " int i;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray() { checkUninitVar("class John\n"