Redundant variable assignment: Fix FN for struct members
This commit is contained in:
parent
4c57f0d33c
commit
13c6489571
|
@ -458,7 +458,8 @@ const Token *CheckOther::checkRedundantAssignmentRecursive(const Token *assign1,
|
||||||
[&](const Token *tok) {
|
[&](const Token *tok) {
|
||||||
if (tok->varId() > 0) {
|
if (tok->varId() > 0) {
|
||||||
assign1LhsVarIds.insert(tok->varId());
|
assign1LhsVarIds.insert(tok->varId());
|
||||||
local &= !nonLocal(tok->variable());
|
if (!Token::simpleMatch(tok->previous(), "."))
|
||||||
|
local &= !nonLocal(tok->variable());
|
||||||
}
|
}
|
||||||
return ChildrenToVisit::op1_and_op2;
|
return ChildrenToVisit::op1_and_op2;
|
||||||
});
|
});
|
||||||
|
|
|
@ -159,6 +159,7 @@ private:
|
||||||
TEST_CASE(incompleteArrayFill);
|
TEST_CASE(incompleteArrayFill);
|
||||||
|
|
||||||
TEST_CASE(redundantVarAssignment);
|
TEST_CASE(redundantVarAssignment);
|
||||||
|
TEST_CASE(redundantVarAssignment_struct);
|
||||||
TEST_CASE(redundantVarAssignment_7133);
|
TEST_CASE(redundantVarAssignment_7133);
|
||||||
TEST_CASE(redundantVarAssignment_stackoverflow);
|
TEST_CASE(redundantVarAssignment_stackoverflow);
|
||||||
TEST_CASE(redundantVarAssignment_lambda);
|
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());
|
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() {
|
void redundantVarAssignment_7133() {
|
||||||
// #7133
|
// #7133
|
||||||
check("sal_Int32 impl_Export() {\n"
|
check("sal_Int32 impl_Export() {\n"
|
||||||
|
|
Loading…
Reference in New Issue