Redundant variable assignment: Fix FN for struct members

This commit is contained in:
Daniel Marjamäki 2018-11-27 18:22:22 +01:00
parent 4c57f0d33c
commit 13c6489571
2 changed files with 16 additions and 1 deletions

View File

@ -458,7 +458,8 @@ const Token *CheckOther::checkRedundantAssignmentRecursive(const Token *assign1,
[&](const Token *tok) {
if (tok->varId() > 0) {
assign1LhsVarIds.insert(tok->varId());
local &= !nonLocal(tok->variable());
if (!Token::simpleMatch(tok->previous(), "."))
local &= !nonLocal(tok->variable());
}
return ChildrenToVisit::op1_and_op2;
});

View File

@ -159,6 +159,7 @@ private:
TEST_CASE(incompleteArrayFill);
TEST_CASE(redundantVarAssignment);
TEST_CASE(redundantVarAssignment_struct);
TEST_CASE(redundantVarAssignment_7133);
TEST_CASE(redundantVarAssignment_stackoverflow);
TEST_CASE(redundantVarAssignment_lambda);
@ -5968,6 +5969,19 @@ private:
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str());
}
void redundantVarAssignment_struct() {
check("struct foo {\n"
" int a,b;\n"
"};\n"
"\n"
"int main() {\n"
" struct foo x;\n"
" x.a = _mm_set1_ps(1.0);\n"
" x.a = _mm_set1_ps(2.0);\n"
"}");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (style) Variable 'x.a' is reassigned a value before the old one has been used.\n", errout.str());
}
void redundantVarAssignment_7133() {
// #7133
check("sal_Int32 impl_Export() {\n"