From b01af012cd486ae82280cc899cf562985cd3e2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 3 Feb 2010 18:37:48 +0100 Subject: [PATCH] Fixed #1342 (Superclass constructors in initializer lists are considered unused functions when superclass has a namespace.) --- lib/checkunusedfunctions.cpp | 9 ++++++++- test/testunusedfunctions.cpp | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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)