Skip to content

Commit

Permalink
Fix #10052 FP parameter can be const (operator()) (#6063)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Mar 2, 2024
1 parent 976bd48 commit 7efe35a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>& c) {\n"
" c[0](5) = 12;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void constParameterCallback() {
Expand Down

0 comments on commit 7efe35a

Please sign in to comment.