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 FP unusedStructMember #7004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mptre
Copy link
Contributor

@mptre mptre commented Nov 14, 2024

Triggering while a function parameter has the same name as a struct member.

@@ -1962,6 +1963,17 @@ class TestUnusedVar : public TestFixture {
errout_str());
}

void structmember26() {
checkStructMemberUsage("struct S {\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Either there are typos in the test case (s -> S), or I don't understand the FP.
As it stands, I would expect a warning for the given code.

Triggering while a function parameter has the same name as a struct member.
@mptre
Copy link
Contributor Author

mptre commented Nov 14, 2024 via email

@chrchr-github
Copy link
Collaborator

With your change applied, will we still warn about S::a?

struct S { int a; };
struct T f(int a) {
    struct T t = {.a = 1};
    return t;
}

@mptre
Copy link
Contributor Author

mptre commented Nov 14, 2024 via email

@mptre
Copy link
Contributor Author

mptre commented Nov 14, 2024 via email

@chrchr-github
Copy link
Collaborator

The root cause is likely the wrong varid:

1: struct S { int a@var1 ; } ;
2: struct T f ( int a@var2 ) {
3: struct T t@var3 ; t@var3 = { .@exprUNIQUE a@var2 = 1 } ;
4: return t@var3 ;
5: }

@chrchr-github
Copy link
Collaborator

There is this similar ticket: https://trac.cppcheck.net/ticket/13123

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.

2 participants