diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 4e614f483..d3c31b18c 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -242,7 +242,8 @@ void CheckClass::createSymbolDatabase() while (found->next()->str() != "(") found = found->next(); - if (Token::Match(found->next()->link(), function.isConst ? ") const {" : ") {")) + if (Token::Match(found->next()->link(), function.isConst ? ") const {" : ") {") || + (function.type == Func::Constructor && Token::Match(found->next()->link(), ") :|{"))) { if (argsMatch(funcArgs, found->tokAt(2), classPath, depth)) { diff --git a/test/testclass.cpp b/test/testclass.cpp index f1216a90d..b83065343 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -53,6 +53,7 @@ private: TEST_CASE(uninitVar7); TEST_CASE(uninitVar8); TEST_CASE(uninitVar9); // ticket #1730 + TEST_CASE(uninitVar10); // ticket #1993 TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1628,6 +1629,19 @@ private: ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Prefs::xasd'\n", errout.str()); } + void uninitVar10() // ticket #1993 + { + checkUninitVar("class A {\n" + "public:\n" + " A();\n" + "private:\n" + " int var1;\n" + " int var2;\n" + "};\n" + "A::A() : var1(0) { }\n"); + ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'A::var2'\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"