Fixed false positive: suspicious operator ',' seen in daca@home
This commit is contained in:
parent
ad9b2741cd
commit
31c800e19e
|
@ -1640,9 +1640,9 @@ static bool isConstTop(const Token *tok)
|
|||
{
|
||||
if (!tok)
|
||||
return false;
|
||||
if (tok == tok->astTop())
|
||||
if (!tok->astParent())
|
||||
return true;
|
||||
if (Token::simpleMatch(tok->astParent(), ";") && tok->astTop() &&
|
||||
if (Token::simpleMatch(tok->astParent(), ";") &&
|
||||
Token::Match(tok->astTop()->previous(), "for|if (") && Token::simpleMatch(tok->astTop()->astOperand2(), ";")) {
|
||||
if (Token::simpleMatch(tok->astParent()->astParent(), ";"))
|
||||
return tok->astParent()->astOperand2() == tok;
|
||||
|
@ -1663,6 +1663,8 @@ void CheckOther::checkIncompleteStatement()
|
|||
continue;
|
||||
if (!isConstTop(tok))
|
||||
continue;
|
||||
if (tok->str() == "," && Token::simpleMatch(tok->astTop()->previous(), "for ("))
|
||||
continue;
|
||||
const Token *rtok = nextAfterAstRightmostLeaf(tok);
|
||||
if (!Token::simpleMatch(tok->astParent(), ";") && !Token::simpleMatch(rtok, ";") &&
|
||||
!Token::Match(tok->previous(), ";|}|{ %any% ;"))
|
||||
|
|
|
@ -84,7 +84,8 @@ private:
|
|||
TEST_CASE(cpp11init3); // #8995
|
||||
TEST_CASE(block); // ({ do_something(); 0; })
|
||||
TEST_CASE(mapindex);
|
||||
TEST_CASE(commaoperator);
|
||||
TEST_CASE(commaoperator1);
|
||||
TEST_CASE(commaoperator2);
|
||||
TEST_CASE(redundantstmts);
|
||||
TEST_CASE(vardecl);
|
||||
TEST_CASE(archive); // ar & x
|
||||
|
@ -336,7 +337,7 @@ private:
|
|||
}
|
||||
|
||||
// #8827
|
||||
void commaoperator() {
|
||||
void commaoperator1() {
|
||||
check("void foo(int,const char*,int);\n"
|
||||
"void f(int value) {\n"
|
||||
" foo(42,\"test\",42),(value&42);\n"
|
||||
|
@ -344,6 +345,13 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ','\n", errout.str());
|
||||
}
|
||||
|
||||
void commaoperator2() {
|
||||
check("void f() {\n"
|
||||
" for(unsigned int a=0, b; a<10; a++ ) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #8451
|
||||
void redundantstmts() {
|
||||
check("void f1(int x) {\n"
|
||||
|
|
Loading…
Reference in New Issue