Fix FP constStatement ',' with Eigen, OpenCV etc. (#3950)

This commit is contained in:
chrchr-github 2022-03-28 22:06:44 +02:00 committed by GitHub
parent 11cbb2eb00
commit 8d49fc252c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -1783,8 +1783,16 @@ static bool isConstStatement(const Token *tok, bool cpp)
return isWithoutSideEffects(cpp, tok->astOperand1()) && isConstStatement(tok->astOperand1(), cpp);
if (Token::simpleMatch(tok, "."))
return isConstStatement(tok->astOperand2(), cpp);
if (Token::simpleMatch(tok, ",")) // warn about const statement on rhs at the top level
return tok->astParent() ? isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp) : isConstStatement(tok->astOperand2(), cpp);
if (Token::simpleMatch(tok, ",")) {
if (tok->astParent()) // warn about const statement on rhs at the top level
return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp);
else {
const Token* lml = previousBeforeAstLeftmostLeaf(tok);
if (lml)
lml = lml->next();
return lml && !isLikelyStream(cpp, lml) && isConstStatement(tok->astOperand2(), cpp);
}
}
if (Token::simpleMatch(tok, "?") && Token::simpleMatch(tok->astOperand2(), ":")) // ternary operator
return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2()->astOperand1(), cpp) && isConstStatement(tok->astOperand2()->astOperand2(), cpp);
if (isBracketAccess(tok) && isWithoutSideEffects(cpp, tok->astOperand1(), /*checkArrayAccess*/ true, /*checkReference*/ false)) {

View File

@ -355,6 +355,12 @@ private:
" for(unsigned int a=0, b; a<10; a++ ) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(int a, int b, int c, int d) {\n"
" Eigen::Vector4d V;\n"
" V << a, b, c, d;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// #8451