diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 33b4b4370..7036fdd98 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -53,8 +53,15 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer) if (tok->fileIndex() != 0) continue; + // token contains a ':' => skip to next ; or { if (tok->str().find(":") != std::string::npos) - continue; + { + while (tok && tok->str().find_first_of(";{")) + tok = tok->next(); + if (tok) + continue; + break; + } // If this is a template function, skip it if (tok->previous() && tok->previous()->str() == ">") diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 6cf409ea2..d04756b7f 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -44,6 +44,7 @@ private: TEST_CASE(template1); TEST_CASE(throwIsNotAFunction); TEST_CASE(unusedError); + TEST_CASE(initializationIsNotAFunction); } void check(const char code[]) @@ -170,6 +171,14 @@ private: "int main()\n"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str()); } + + void initializationIsNotAFunction() + { + check("struct B: N::A {\n" + " B(): N::A() {};\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestUnusedFunctions)