Fix #11257 FN constStatement with misused comma (#4365)

This commit is contained in:
chrchr-github 2022-08-16 22:10:58 +02:00 committed by GitHub
parent 31d704e4bc
commit 3dc2c0bd42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -1866,6 +1866,8 @@ static bool isConstTop(const Token *tok)
if (!bracTok->astParent())
return true;
}
if (tok->str() == "," && tok->astParent() && tok->astParent()->isAssignmentOp())
return true;
return false;
}
@ -1908,7 +1910,8 @@ void CheckOther::checkIncompleteStatement()
!Token::Match(tok->previous(), ";|}|{ %any% ;") &&
!(mTokenizer->isCPP() && tok->isCast() && !tok->astParent()) &&
!Token::simpleMatch(tok->tokAt(-2), "for (") &&
!Token::Match(tok->tokAt(-1), "%var% ["))
!Token::Match(tok->tokAt(-1), "%var% [") &&
!(tok->str() == "," && tok->astParent() && tok->astParent()->isAssignmentOp()))
continue;
// Skip statement expressions
if (Token::simpleMatch(rtok, "; } )"))

View File

@ -357,13 +357,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
// #8827
void commaoperator1() {
check("void foo(int,const char*,int);\n"
check("void foo(int,const char*,int);\n" // #8827
"void f(int value) {\n"
" foo(42,\"test\",42),(value&42);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ',', result is not used.\n", errout.str());
check("int f() {\n" // #11257
" int y;\n"
" y = (3, 4);\n"
" return y;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ',', result is not used.\n", errout.str());
}
void commaoperator2() {