From be6ec8fd6027a5e09a3bb589874d1c684eef3cea Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 17 Oct 2024 00:15:38 +0200 Subject: [PATCH] Fix #13226 FP constParameterReference with array member (regression) (#6921) --- lib/astutils.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 03b1fbf4749..a80787f8d3a 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2601,7 +2601,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, const Token *tok2 = tok; int derefs = 0; while ((tok2->astParent() && tok2->astParent()->isUnaryOp("*")) || - (Token::simpleMatch(tok2->astParent(), ".") && !Token::simpleMatch(tok2->astParent()->astParent(), "(")) || + (Token::simpleMatch(tok2->astParent(), ".") && !Token::Match(tok2->astParent()->astParent(), "[(,]")) || (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") || (Token::simpleMatch(tok2->astParent(), "[") && tok2 == tok2->astParent()->astOperand1())) { if (tok2->astParent() && (tok2->astParent()->isUnaryOp("*") || (astIsLHS(tok2) && tok2->astParent()->originalName() == "->"))) diff --git a/test/testother.cpp b/test/testother.cpp index 8f7fce676ec..42a141aab55 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3743,6 +3743,13 @@ class TestOther : public TestFixture { " return lam();\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S { int x[3]; };\n" // #13226 + "void g(int a, int* b);\n" + "void f(int a, S& s) {\n" + " return g(a, s.x);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {