-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
Conversation
Please rebase - I disabled the failing test for Cygwin. |
continue; | ||
|
||
const Token *tok = var->nameToken()->linkAt(-1); | ||
if (!Token::Match(tok, "] %assign%")) |
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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"
No description provided.