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)
|
if (!tok)
|
||||||
return false;
|
return false;
|
||||||
if (tok == tok->astTop())
|
if (!tok->astParent())
|
||||||
return true;
|
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(), ";")) {
|
Token::Match(tok->astTop()->previous(), "for|if (") && Token::simpleMatch(tok->astTop()->astOperand2(), ";")) {
|
||||||
if (Token::simpleMatch(tok->astParent()->astParent(), ";"))
|
if (Token::simpleMatch(tok->astParent()->astParent(), ";"))
|
||||||
return tok->astParent()->astOperand2() == tok;
|
return tok->astParent()->astOperand2() == tok;
|
||||||
|
@ -1663,6 +1663,8 @@ void CheckOther::checkIncompleteStatement()
|
||||||
continue;
|
continue;
|
||||||
if (!isConstTop(tok))
|
if (!isConstTop(tok))
|
||||||
continue;
|
continue;
|
||||||
|
if (tok->str() == "," && Token::simpleMatch(tok->astTop()->previous(), "for ("))
|
||||||
|
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% ;"))
|
||||||
|
|
|
@ -84,7 +84,8 @@ private:
|
||||||
TEST_CASE(cpp11init3); // #8995
|
TEST_CASE(cpp11init3); // #8995
|
||||||
TEST_CASE(block); // ({ do_something(); 0; })
|
TEST_CASE(block); // ({ do_something(); 0; })
|
||||||
TEST_CASE(mapindex);
|
TEST_CASE(mapindex);
|
||||||
TEST_CASE(commaoperator);
|
TEST_CASE(commaoperator1);
|
||||||
|
TEST_CASE(commaoperator2);
|
||||||
TEST_CASE(redundantstmts);
|
TEST_CASE(redundantstmts);
|
||||||
TEST_CASE(vardecl);
|
TEST_CASE(vardecl);
|
||||||
TEST_CASE(archive); // ar & x
|
TEST_CASE(archive); // ar & x
|
||||||
|
@ -336,7 +337,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// #8827
|
// #8827
|
||||||
void commaoperator() {
|
void commaoperator1() {
|
||||||
check("void foo(int,const char*,int);\n"
|
check("void foo(int,const char*,int);\n"
|
||||||
"void f(int value) {\n"
|
"void f(int value) {\n"
|
||||||
" foo(42,\"test\",42),(value&42);\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());
|
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
|
// #8451
|
||||||
void redundantstmts() {
|
void redundantstmts() {
|
||||||
check("void f1(int x) {\n"
|
check("void f1(int x) {\n"
|
||||||
|
|
Loading…
Reference in New Issue