diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ec3bce8ba..64190cec8 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -964,7 +964,7 @@ void CheckClass::SpaceInfo::initializeVarList(const Func &func, std::list::const_iterator it; for (it = functionList.begin(); it != functionList.end(); ++it) { - if (ftok->str() == it->tokenDef->str()) + if (ftok->str() == it->tokenDef->str() && it->type != Func::Constructor) break; } diff --git a/test/testclass.cpp b/test/testclass.cpp index 0e6c06e88..a5678866a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -55,6 +55,7 @@ private: TEST_CASE(uninitVar9); // ticket #1730 TEST_CASE(uninitVar10); // ticket #1993 TEST_CASE(uninitVar11); + TEST_CASE(uninitVar12); // ticket #2078 TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1677,6 +1678,24 @@ private: ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'A::var'\n", errout.str()); } + void uninitVar12() // ticket #2078 + { + checkUninitVar("class Point\n" + "{\n" + "public:\n" + " Point()\n" + " {\n" + " Point(0, 0);\n" + " }\n" + " Point(int x, int y)\n" + " : x(x), y(y)\n" + " {}\n" + " int x, y;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Point::x'\n" + "[test.cpp:4]: (style) Member variable not initialized in the constructor 'Point::y'\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"