Fixed #1994 (False 'Found obsolete function' positive)

This commit is contained in:
Daniel Marjamäki 2010-08-29 12:01:32 +02:00
parent 6e676fdd98
commit 02939c78f8
2 changed files with 22 additions and 12 deletions

View File

@ -41,7 +41,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
std::list< std::pair<const std::string, const std::string> >::const_iterator it(_obsoleteFunctions.begin()), itend(_obsoleteFunctions.end());
for (; it!=itend; ++it)
{
if (tok->strAt(1) == it->first && tok->strAt(2) == "(" && tok->tokAt(1)->varId() == 0 && !tok->tokAt(0)->isName() && tok->strAt(0) != "." && tok->strAt(0) != "::")
if (tok->strAt(1) == it->first && tok->strAt(2) == "(" && tok->tokAt(1)->varId() == 0 && !tok->tokAt(0)->isName() && !Token::Match(tok, ".|::|:|,"))
{
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
break;

View File

@ -33,6 +33,18 @@ public:
private:
void run()
{
TEST_CASE(testbsd_signal);
TEST_CASE(testgethostbyname);
TEST_CASE(testgethostbyaddr);
TEST_CASE(testusleep);
TEST_CASE(testindex);
TEST_CASE(testrindex);
// no false positives for variables
TEST_CASE(var);
}
void check(const char code[])
@ -60,16 +72,6 @@ private:
checkObsoleteFunctions.obsoleteFunctions();
}
void run()
{
TEST_CASE(testbsd_signal);
TEST_CASE(testgethostbyname);
TEST_CASE(testgethostbyaddr);
TEST_CASE(testusleep);
TEST_CASE(testindex);
TEST_CASE(testrindex);
}
void testbsd_signal()
{
check("void f()\n"
@ -179,7 +181,15 @@ private:
}
void var()
{
check("class Fred {\n"
"public:\n"
" Fred() : index(0) { }\n"
" int index;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};