From b6aca47e11d4c15454b470a3b34ae8dc5f7fea51 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 27 Oct 2010 19:28:15 +0200 Subject: [PATCH] Fixed #1195 (Uninitialized member variable not detected 'std::vector *ints;') --- lib/checkclass.cpp | 4 +++- test/testclass.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3022dce7c..7a895f44b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -722,7 +722,6 @@ void CheckClass::SpaceInfo::getVarList() else if (Token::Match(next, "%type% :: %type% <") || Token::Match(next, "%type% <")) { - isClass = true; // find matching ">" int level = 0; for (; next; next = next->next()) @@ -737,7 +736,10 @@ void CheckClass::SpaceInfo::getVarList() } } if (next && Token::Match(next, "> %var% ;")) + { + isClass = true; vartok = next->tokAt(1); + } else if (next && Token::Match(next, "> * %var% ;")) vartok = next->tokAt(2); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 8a9a10cba..add63abe8 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -56,6 +56,7 @@ private: TEST_CASE(uninitVar10); // ticket #1993 TEST_CASE(uninitVar11); TEST_CASE(uninitVar12); // ticket #2078 + TEST_CASE(uninitVar13); // ticket #1195 TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1700,6 +1701,18 @@ private: "[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Point::y'\n", errout.str()); } + void uninitVar13() // ticket #1195 + { + checkUninitVar("class A {\n" + "private:\n" + " std::vector *ints;\n" + "public:\n" + " A()\n" + " {}\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable not initialized in the constructor 'A::ints'\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"