Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10052 FP parameter can be const (operator()) #6063

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading