From 11d003c903ab390e0749e3daf400a29c3331d438 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:02:38 +0100 Subject: [PATCH 1/2] Update testother.cpp --- test/testother.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 0b403bbb426..3126932038f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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 From 5ee011516bd215b7f6e0dd7706510adc4a71fc3d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:03:36 +0100 Subject: [PATCH 2/2] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 90a487dc9b0..8dc8e81b0c4 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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();