Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ void CheckOther::checkRedundantAssignment()
// Is there a redundant assignment?
const Token *start;
if (tok->isAssignmentOp())
start = tok->next();
start = tok->astOperand2();
else
start = tok->findExpressionStartEndTokens().second->next();

Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11032,6 +11032,15 @@ class TestOther : public TestFixture {
" a = x;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("int f(int a, int b, int c) {\n" // #4491
" int x = a + b;\n"
" if (c)\n"
" x = a + b;\n"
" return x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:9]: (style) Variable 'x' is assigned an expression that holds the same value. [redundantAssignment]\n",
errout_str());
}

void varFuncNullUB() { // #4482
Expand Down