Fixed #4837 (False positive: Assert statement calls a function which may have desired side effects (local variable))
This commit is contained in:
parent
8862864062
commit
aa25d1e0af
|
@ -68,7 +68,7 @@ void CheckAssert::assertWithSideEffects()
|
||||||
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||||
if (tok2->type() != Token::eAssignmentOp && tok2->type() != Token::eIncDecOp) continue;
|
if (tok2->type() != Token::eAssignmentOp && tok2->type() != Token::eIncDecOp) continue;
|
||||||
const Variable* var = tok2->previous()->variable();
|
const Variable* var = tok2->previous()->variable();
|
||||||
if (!var) continue;
|
if (!var || var->isLocal()) continue;
|
||||||
|
|
||||||
std::vector<const Token*> returnTokens; // find all return statements
|
std::vector<const Token*> returnTokens; // find all return statements
|
||||||
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
|
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
|
||||||
|
|
|
@ -68,6 +68,15 @@ private:
|
||||||
"assert(foo() == 3); \n"
|
"assert(foo() == 3); \n"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void functionCallInAssert() {
|
||||||
|
@ -138,4 +147,4 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestAssert)
|
REGISTER_TEST(TestAssert)
|
||||||
|
|
Loading…
Reference in New Issue