Fixed #431 (Unused private function, wrong line when two functions with same name)

This commit is contained in:
Daniel Marjamäki 2009-07-07 08:55:14 +02:00
parent 9d1d7ebf8d
commit ddc1ad7d4d
2 changed files with 23 additions and 5 deletions

View File

@ -544,13 +544,13 @@ void CheckClass::privateFunctions()
else if (Token::Match(tok2, "%var% ("))
{
// Remove function from FuncList
for (std::list<const Token *>::iterator it = FuncList.begin(); it != FuncList.end(); ++it)
std::list<const Token *>::iterator it = FuncList.begin();
while (it != FuncList.end())
{
if (tok2->str() == (*it)->str())
{
FuncList.remove(*it);
break;
}
FuncList.erase(it++);
else
it++;
}
}
}

View File

@ -45,6 +45,7 @@ private:
TEST_CASE(ctor);
TEST_CASE(classInClass);
TEST_CASE(sameFunctionNames);
}
@ -254,6 +255,23 @@ private:
ASSERT_EQUALS("", errout.str());
}
void sameFunctionNames()
{
check("class A\n"
"{\n"
"public:\n"
" void a()\n"
" {\n"
" f(1);\n"
" }\n"
"\n"
"private:\n"
" void f() { }\n"
" void f(int) { }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestUnusedPrivateFunction)