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 #12618 FN variableScope with member or array access #6301

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

chrchr-github
Copy link
Collaborator

No description provided.

check("struct S { int a; };\n" // #12618
"int f(const S* s, int i) {\n"
" int x = s->a;\n"
" const int b[] = { 1, 2, 3 };\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even the scope of 'b' could be reduced.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. but that requires that scope of y can be reduced. I don't know if we will warn about b if y is moved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't warn for arrays because of

if (Token::Match(tok, "= %varid%", var->declarationId()) && (var->isArray() || var->isPointer() || (var->valueType() && var->valueType()->container))) // Create a copy of array/pointer. Bailout, because the memory it points to might be necessary in outer scope
            return false;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok it's a bailout we should fix.. good that the comment says "bailout" explicitly so we can search for it..

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@chrchr-github chrchr-github merged commit 5c97641 into danmar:main Apr 18, 2024
64 checks passed
@chrchr-github chrchr-github deleted the chr_Fix12618 branch April 18, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants