Skip to content

Commit b01af01

Browse files
author
Daniel Marjamäki
committed
Fixed cppcheck-opensource#1342 (Superclass constructors in initializer lists are considered unused functions when superclass has a namespace.)
1 parent f2eac90 commit b01af01

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎lib/checkunusedfunctions.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer)
5353
if (tok->fileIndex() != 0)
5454
continue;
5555

56+
// token contains a ':' => skip to next ; or {
5657
if (tok->str().find(":") != std::string::npos)
57-
continue;
58+
{
59+
while (tok && tok->str().find_first_of(";{"))
60+
tok = tok->next();
61+
if (tok)
62+
continue;
63+
break;
64+
}
5865

5966
// If this is a template function, skip it
6067
if (tok->previous() && tok->previous()->str() == ">")

‎test/testunusedfunctions.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TestUnusedFunctions : public TestFixture
4444
TEST_CASE(template1);
4545
TEST_CASE(throwIsNotAFunction);
4646
TEST_CASE(unusedError);
47+
TEST_CASE(initializationIsNotAFunction);
4748
}
4849

4950
void check(const char code[])
@@ -170,6 +171,14 @@ class TestUnusedFunctions : public TestFixture
170171
"int main()\n");
171172
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
172173
}
174+
175+
void initializationIsNotAFunction()
176+
{
177+
check("struct B: N::A {\n"
178+
" B(): N::A() {};\n"
179+
"};\n");
180+
ASSERT_EQUALS("", errout.str());
181+
}
173182
};
174183

175184
REGISTER_TEST(TestUnusedFunctions)

0 commit comments

Comments
 (0)