From 571479ae6cf282b74bb4c18d99f2455049435295 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 6 Apr 2022 13:10:42 +0200 Subject: [PATCH 1/2] Fix FP constStatement with comma operator --- 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 1e0303b9aea..a94ea363fb8 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 e3b97c9966a..46de9046b12 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -396,6 +396,16 @@ class TestIncompleteStatement : public TestFixture { " 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 From 0a21f7251662550905dc50858aab0c8e95db42ed Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 6 Apr 2022 13:12:24 +0200 Subject: [PATCH 2/2] Format --- test/testincompletestatement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 46de9046b12..8f6bc0e0c34 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -398,7 +398,7 @@ class TestIncompleteStatement : public TestFixture { ASSERT_EQUALS("", errout.str()); check("struct V {\n" - " Eigen::Vector3d & operator[](int i) { return v[i]; }\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"