Fix FP constStatement with comma operator (#3978)

* Fix FP constStatement with comma operator

* Format
This commit is contained in:
chrchr-github 2022-04-06 16:58:17 +02:00 committed by GitHub
parent 64a7ba3c4c
commit b73aeeda0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1792,11 +1792,11 @@ static bool isConstStatement(const Token *tok, bool cpp)
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);
const Token* lml = previousBeforeAstLeftmostLeaf(tok); // don't warn about matrix/vector assignment (e.g. Eigen)
if (lml)
lml = lml->next();
const Token* stream = lml;
while (stream && Token::Match(stream->astParent(), ".|[|("))
while (stream && Token::Match(stream->astParent(), ".|[|(|*"))
stream = stream->astParent();
return (!stream || !isLikelyStream(cpp, stream)) && isConstStatement(tok->astOperand2(), cpp);
}

View File

@ -396,6 +396,16 @@ private:
" a.b[4][3].c()->d << x , y, z;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct V {\n"
" Eigen::Vector3d& operator[](int i) { return v[i]; }\n"
" void f(int a, int b, int c);\n"
" Eigen::Vector3d v[1];\n"
"};\n"
"void V::f(int a, int b, int c) {\n"
" (*this)[0] << a, b, c;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// #8451