From 8d49fc252cf256c7c3d698f691fbe1c6967677d3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:06:44 +0200 Subject: [PATCH] Fix FP constStatement ',' with Eigen, OpenCV etc. (#3950) --- lib/checkother.cpp | 12 ++++++++++-- test/testincompletestatement.cpp | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 036e817c9..812f006dc 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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)) { diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 768d7fe99..0e7bdb6bc 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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