Fixed 2071 (false positive: object destroyed immediately (when using '= { ... }'))

Simplified check within CheckOther::checkMisusedScopedObject() as a result.
This commit is contained in:
Pete Johns 2010-10-04 08:16:11 +11:00
parent cd8ef1cded
commit 4bf9ff26ea
2 changed files with 15 additions and 2 deletions

View File

@ -3893,9 +3893,8 @@ void CheckOther::checkMisusedScopedObject()
if (withinFunction
&& Token::Match(tok, "[;{}] %var% (")
&& Token::Match(tok->tokAt(2)->link(), ") ;")
&& isIdentifierObjectType(tok)
&& !Token::Match(tok->tokAt(2)->link(), ") ( %var%")
&& !Token::simpleMatch(tok->tokAt(2)->link(), ") .")
)
{
tok = tok->next();

View File

@ -114,6 +114,7 @@ private:
TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);
TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);
TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);
TEST_CASE(trac2071);
}
void check(const char code[])
@ -3155,6 +3156,19 @@ private:
);
ASSERT_EQUALS("", errout.str());
}
void trac2071()
{
check("void f() {\n"
" struct AB {\n"
" AB(int a) { }\n"
" };\n"
"\n"
" const AB ab[3] = { AB(0), AB(1), AB(2) };\n"
"}\n"
);
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestOther)