Skip to content

Commit 3747685

Browse files
Fix #4491 FN redundantAssignment: assigning same value twice (#7955)
1 parent 359ae22 commit 3747685

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ void CheckOther::checkRedundantAssignment()
681681
// Is there a redundant assignment?
682682
const Token *start;
683683
if (tok->isAssignmentOp())
684-
start = tok->next();
684+
start = tok->astOperand2();
685685
else
686686
start = tok->findExpressionStartEndTokens().second->next();
687687

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11032,6 +11032,15 @@ class TestOther : public TestFixture {
1103211032
" a = x;\n"
1103311033
"}\n");
1103411034
ASSERT_EQUALS("", errout_str());
11035+
11036+
check("int f(int a, int b, int c) {\n" // #4491
11037+
" int x = a + b;\n"
11038+
" if (c)\n"
11039+
" x = a + b;\n"
11040+
" return x;\n"
11041+
"}\n");
11042+
ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:9]: (style) Variable 'x' is assigned an expression that holds the same value. [redundantAssignment]\n",
11043+
errout_str());
1103511044
}
1103611045

1103711046
void varFuncNullUB() { // #4482

0 commit comments

Comments
 (0)