Fixed #4837 (False positive: Assert statement calls a function which may have desired side effects (local variable))

This commit is contained in:
Frank Zingsheim 2013-06-05 22:10:43 +02:00
parent 8862864062
commit aa25d1e0af
2 changed files with 11 additions and 2 deletions

View File

@ -68,7 +68,7 @@ void CheckAssert::assertWithSideEffects()
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
if (tok2->type() != Token::eAssignmentOp && tok2->type() != Token::eIncDecOp) continue;
const Variable* var = tok2->previous()->variable();
if (!var) continue;
if (!var || var->isLocal()) continue;
std::vector<const Token*> returnTokens; // find all return statements
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {

View File

@ -68,6 +68,15 @@ private:
"assert(foo() == 3); \n"
);
ASSERT_EQUALS("", errout.str());
check(
"int foo(int a) {\n"
" int b=a+1;\n"
" return b;\n"
"}\n"
"assert(foo(1) == 2); \n"
);
ASSERT_EQUALS("", errout.str());
}
void functionCallInAssert() {
@ -138,4 +147,4 @@ private:
}
};
REGISTER_TEST(TestAssert)
REGISTER_TEST(TestAssert)