Avoid constStatement false positives for 'foo() || x=5'. Found in daca@home.
This commit is contained in:
parent
f956dee58a
commit
bf3833dad5
|
@ -1665,6 +1665,27 @@ void CheckOther::checkIncompleteStatement()
|
||||||
continue;
|
continue;
|
||||||
if (tok->str() == "," && Token::simpleMatch(tok->astTop()->previous(), "for ("))
|
if (tok->str() == "," && Token::simpleMatch(tok->astTop()->previous(), "for ("))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Do not warn for statement when both lhs and rhs has side effects:
|
||||||
|
// dostuff() || x=213;
|
||||||
|
if (Token::Match(tok, "%oror%|&&")) {
|
||||||
|
bool warn = false;
|
||||||
|
visitAstNodes(tok, [&warn](const Token *child) {
|
||||||
|
if (Token::Match(child, "%oror%|&&"))
|
||||||
|
return ChildrenToVisit::op1_and_op2;
|
||||||
|
if (child->isAssignmentOp())
|
||||||
|
return ChildrenToVisit::none;
|
||||||
|
if (child->tokType() == Token::Type::eIncDecOp)
|
||||||
|
return ChildrenToVisit::none;
|
||||||
|
if (Token::Match(child->previous(), "%name% ("))
|
||||||
|
return ChildrenToVisit::none;
|
||||||
|
warn = true;
|
||||||
|
return ChildrenToVisit::done;
|
||||||
|
});
|
||||||
|
if (!warn)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const Token *rtok = nextAfterAstRightmostLeaf(tok);
|
const Token *rtok = nextAfterAstRightmostLeaf(tok);
|
||||||
if (!Token::simpleMatch(tok->astParent(), ";") && !Token::simpleMatch(rtok, ";") &&
|
if (!Token::simpleMatch(tok->astParent(), ";") && !Token::simpleMatch(rtok, ";") &&
|
||||||
!Token::Match(tok->previous(), ";|}|{ %any% ;"))
|
!Token::Match(tok->previous(), ";|}|{ %any% ;"))
|
||||||
|
|
|
@ -90,6 +90,7 @@ private:
|
||||||
TEST_CASE(vardecl);
|
TEST_CASE(vardecl);
|
||||||
TEST_CASE(archive); // ar & x
|
TEST_CASE(archive); // ar & x
|
||||||
TEST_CASE(ast);
|
TEST_CASE(ast);
|
||||||
|
TEST_CASE(oror); // dostuff() || x=32;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test1() {
|
void test1() {
|
||||||
|
@ -423,6 +424,13 @@ private:
|
||||||
check("struct c { void a() const { for (int x=0; x;); } };", true);
|
check("struct c { void a() const { for (int x=0; x;); } };", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void oror() {
|
||||||
|
check("void foo() {\n"
|
||||||
|
" params_given (params, \"overrides\") || (overrides = \"1\");\n"
|
||||||
|
"}", true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestIncompleteStatement)
|
REGISTER_TEST(TestIncompleteStatement)
|
||||||
|
|
Loading…
Reference in New Issue