diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 9cb66b8e1..dde5c8a6b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; }); diff --git a/test/testother.cpp b/test/testother.cpp index 0bca64f58..d4d385503 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"