From 7efe35ab308d10b5904bea50957fcabcb64881f0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 2 Mar 2024 08:44:14 +0100 Subject: [PATCH] Fix #10052 FP parameter can be const (operator()) (#6063) --- lib/astutils.cpp | 2 ++ test/testother.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 70cc971ca15..1e75552ec4d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2669,6 +2669,8 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, ftok = ftok->astParent(); if (ftok && Token::Match(ftok->link(), ")|} !!{")) { + if (ftok->str() == "(" && Token::simpleMatch(ftok->astOperand1(), "[")) // operator() on array element, bail out + return true; const Token * ptok = tok2; while (Token::Match(ptok->astParent(), ".|::|[")) ptok = ptok->astParent(); diff --git a/test/testother.cpp b/test/testother.cpp index c1b7260e9ac..e85cd590bd5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3544,6 +3544,14 @@ class TestOther : public TestFixture { " const S& s(str);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct C {\n" // #10052 + " int& operator()(int);\n" + "};\n" + "void f(std::vector& c) {\n" + " c[0](5) = 12;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void constParameterCallback() {