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 #13107: FP unusedStructMember with structured binding #7177

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ludviggunne
Copy link
Contributor

No description provided.

lib/checkunusedvar.cpp Outdated Show resolved Hide resolved
lib/checkunusedvar.cpp Outdated Show resolved Hide resolved
@firewave
Copy link
Collaborator

firewave commented Jan 5, 2025

Please rebase - I disabled the failing test for Cygwin.

continue;

const Token *tok = var->nameToken()->linkAt(-1);
if (!Token::Match(tok, "] %assign%"))
Copy link
Owner

Choose a reason for hiding this comment

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

I would like that we handle structured bindings in range for loops also.

@@ -1534,6 +1534,26 @@ void CheckUnusedVar::checkStructMemberUsage()
if (bailout)
continue;

// Bailout if struct is used in structured binding
for (const Variable *var : symbolDatabase->variableList()) {
if (!var || !Token::Match(var->typeStartToken(), "auto &|&&| [ %varid%", var->declarationId()))
Copy link
Owner

Choose a reason for hiding this comment

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

so the %varid% is for performance reasons right?

@@ -2024,6 +2025,27 @@ class TestUnusedVar : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void structmemberStructuredBinding() { // #13107
checkStructMemberUsage("struct S { int a, b; };\n"
Copy link
Owner

Choose a reason for hiding this comment

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

can this testcase be reduced.. maybe:

"struct S { int a, b; };\n"
"void foo(const S& s) {\n"
"    auto [x,y] = s;\n"
"    dostuff(x,y);\n"
"}\n"

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