diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 6d02469f8..75050d540 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -97,6 +97,12 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1) varname = next->strAt(2); } + // Pointer? + else if (Token::Match(next, "%type% %type% * %var% ;")) + { + varname = next->strAt(3); + } + // If the varname was set in one of the two if-block above, create a entry for this variable.. if (varname) { diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index e37395d8b..02d1c7320 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(initvar_same_classname); // BUG 2208157 TEST_CASE(initvar_chained_assign); // BUG 2270433 TEST_CASE(initvar_2constructors); // BUG 2270353 + TEST_CASE(initvar_constvar); TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor @@ -296,6 +297,20 @@ private: } + void initvar_constvar() + { + check("class Fred\n" + "{\n" + "public:\n" + " const char *s;\n" + " Fred();\n" + "};\n" + "Fred::Fred()\n" + "{ }"); + ASSERT_EQUALS(std::string("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::s'\n"), errout.str()); + } + + void initvar_private_constructor() { check("class Fred\n"