diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 5b2320ee3..067e587d8 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -364,9 +364,10 @@ void CheckClass::initializeVarList(const Function &func, std::list // Class constructor.. initializing variables like this // clKalle::clKalle() : var(value) { } if (initList) { - if (level == 0 && Token::Match(ftok, "%var% (")) - initVar(ftok->str(), scope, usage); - else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x) + if (level == 0 && Token::Match(ftok, "%var% (")) { + if (ftok->strAt(2) != ")") + initVar(ftok->str(), scope, usage); + } else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x) assignVar(ftok->str(), scope, usage); else if (ftok->str() == "(") diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 6d9f7a160..17988607b 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -109,6 +109,7 @@ private: TEST_CASE(uninitVar22); // ticket #3043 TEST_CASE(uninitVar23); // ticket #3702 TEST_CASE(uninitVar24); // ticket #3190 + TEST_CASE(uninitVar25); // ticket #4383 TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1616,6 +1617,16 @@ private: "[test.cpp:12]: (warning) Member variable 'Sub::b' is not initialized in the constructor.\n", errout.str()); } + void uninitVar25() { // ticket #4383 + check("class Fred {\n" + " bool b;\n" + "public:\n" + " Fred() : b() { }\n" + "};\n"); + + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::b' is not initialized in the constructor.\n" , errout.str()); + } + void uninitVarArray1() { check("class John\n" "{\n"