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 11889: FP knownArgument with array element #5395

Merged
merged 2 commits into from
Sep 2, 2023
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
3 changes: 1 addition & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3704,8 +3704,7 @@ static bool isVariableExpression(const Token* tok)
return isVariableExpression(tok->astOperand1()) &&
isVariableExpression(tok->astOperand2());
if (Token::simpleMatch(tok, "["))
return isVariableExpression(tok->astOperand1()) &&
tok->astOperand2() && tok->astOperand2()->hasKnownIntValue();
return isVariableExpression(tok->astOperand1());
return false;
}

Expand Down
14 changes: 14 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11041,6 +11041,20 @@ class TestOther : public TestFixture {
" if (g(k(i))) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// #11889
check("struct S {\n"
" int a[5];\n"
" void f(int i);\n"
"}\n"
"void g(int);\n"
"void S::f(int i) {\n"
" if (a[i] == 1) {\n"
" a[i] = 0;\n"
" g(a[i]);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void knownArgumentHiddenVariableExpression() {
Expand Down
Loading