Fixed #2661 (False positive: object destroyed immediately)
This commit is contained in:
parent
2613780b85
commit
27506b4231
|
@ -2951,11 +2951,18 @@ static bool isFunction(const std::string &name, const Token *startToken)
|
|||
for (const Token *tok = startToken; tok; tok = tok->next())
|
||||
{
|
||||
// skip executable scopes etc
|
||||
if (tok->str() == "(" || tok->str() == "{")
|
||||
if (tok->str() == "(")
|
||||
{
|
||||
tok = tok->link();
|
||||
if (Token::simpleMatch(tok, ") {"))
|
||||
tok = tok->next()->link();
|
||||
else if (Token::simpleMatch(tok, ") const {"))
|
||||
tok = tok->tokAt(2)->link();
|
||||
}
|
||||
|
||||
// function declaration/implementation found
|
||||
if (Token::simpleMatch(tok, pattern1.c_str()))
|
||||
if ((tok->str() == "*" || (tok->isName() && tok->str().find(":") ==std::string::npos))
|
||||
&& Token::simpleMatch(tok->next(), pattern1.c_str()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -82,7 +82,8 @@ private:
|
|||
TEST_CASE(testScanf2);
|
||||
|
||||
TEST_CASE(trac1132);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickFunction);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);
|
||||
TEST_CASE(testMisusedScopeObjectPicksClass);
|
||||
TEST_CASE(testMisusedScopeObjectPicksStruct);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickIf);
|
||||
|
@ -1647,7 +1648,7 @@ private:
|
|||
ASSERT_EQUALS("[trac1132.cpp:16]: (error) instance of \"Lock\" object destroyed immediately\n", errout.str());
|
||||
}
|
||||
|
||||
void testMisusedScopeObjectDoesNotPickFunction()
|
||||
void testMisusedScopeObjectDoesNotPickFunction1()
|
||||
{
|
||||
check("int main ( )\n"
|
||||
"{\n"
|
||||
|
@ -1658,6 +1659,24 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testMisusedScopeObjectDoesNotPickFunction2()
|
||||
{
|
||||
check("struct error {\n"
|
||||
" error() {}\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class parser {\n"
|
||||
"public:\n"
|
||||
" void error() const {}\n"
|
||||
"\n"
|
||||
" void foo() const {\n"
|
||||
" error();\n"
|
||||
" }\n"
|
||||
"};\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testMisusedScopeObjectPicksClass()
|
||||
{
|
||||
check("class NotAFunction ;\n"
|
||||
|
@ -1803,7 +1822,7 @@ private:
|
|||
"}\n";
|
||||
|
||||
check(code, "test.cpp");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:13]: (error) instance of \"Init\" object destroyed immediately\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void trac2084()
|
||||
|
|
Loading…
Reference in New Issue