Skip to content

Commit 02939c7

Browse files
author
Daniel Marjamäki
committed
Fixed cppcheck-opensource#1994 (False 'Found obsolete function' positive)
1 parent 6e676fd commit 02939c7

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

lib/checkobsoletefunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
4141
std::list< std::pair<const std::string, const std::string> >::const_iterator it(_obsoleteFunctions.begin()), itend(_obsoleteFunctions.end());
4242
for (; it!=itend; ++it)
4343
{
44-
if (tok->strAt(1) == it->first && tok->strAt(2) == "(" && tok->tokAt(1)->varId() == 0 && !tok->tokAt(0)->isName() && tok->strAt(0) != "." && tok->strAt(0) != "::")
44+
if (tok->strAt(1) == it->first && tok->strAt(2) == "(" && tok->tokAt(1)->varId() == 0 && !tok->tokAt(0)->isName() && !Token::Match(tok, ".|::|:|,"))
4545
{
4646
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
4747
break;

test/testobsoletefunctions.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ class TestObsoleteFunctions : public TestFixture
3333

3434
private:
3535

36+
void run()
37+
{
38+
TEST_CASE(testbsd_signal);
39+
TEST_CASE(testgethostbyname);
40+
TEST_CASE(testgethostbyaddr);
41+
TEST_CASE(testusleep);
42+
TEST_CASE(testindex);
43+
TEST_CASE(testrindex);
44+
45+
// no false positives for variables
46+
TEST_CASE(var);
47+
}
3648

3749

3850
void check(const char code[])
@@ -60,16 +72,6 @@ class TestObsoleteFunctions : public TestFixture
6072
checkObsoleteFunctions.obsoleteFunctions();
6173
}
6274

63-
void run()
64-
{
65-
TEST_CASE(testbsd_signal);
66-
TEST_CASE(testgethostbyname);
67-
TEST_CASE(testgethostbyaddr);
68-
TEST_CASE(testusleep);
69-
TEST_CASE(testindex);
70-
TEST_CASE(testrindex);
71-
}
72-
7375
void testbsd_signal()
7476
{
7577
check("void f()\n"
@@ -179,7 +181,15 @@ class TestObsoleteFunctions : public TestFixture
179181
}
180182

181183

182-
184+
void var()
185+
{
186+
check("class Fred {\n"
187+
"public:\n"
188+
" Fred() : index(0) { }\n"
189+
" int index;\n"
190+
"};\n");
191+
ASSERT_EQUALS("", errout.str());
192+
}
183193

184194
};
185195

0 commit comments

Comments
 (0)