From b73aeeda0e16268e9d65f51b5db429a4da50ff85 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 6 Apr 2022 16:58:17 +0200 Subject: [PATCH] Fix FP constStatement with comma operator (#3978) * Fix FP constStatement with comma operator * Format --- lib/checkother.cpp | 4 ++-- test/testincompletestatement.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1e0303b9a..a94ea363f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index e3b97c996..8f6bc0e0c 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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