From 757763d8ee4937fc4a20887891aebc70efb874e1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 10:21:12 +0200 Subject: [PATCH 1/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 78351a229c0..c197dfb451b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -633,7 +633,7 @@ void CheckOtherImpl::checkRedundantAssignment() if (Token::Match(rhs, ":: %name%") && rhs->hasKnownIntValue()) return ChildrenToVisit::none; if (rhs->isCast()) - return ChildrenToVisit::op2; + return rhs->astOperand2() ? ChildrenToVisit::op2 : ChildrenToVisit::op1; trivial = false; return ChildrenToVisit::done; }); From 2c06401c9b53f6b4c25deee3d14244eefdcd54ca Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 10:22:07 +0200 Subject: [PATCH 2/2] Update testother.cpp --- test/testother.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 1c1c8640461..886c19fc0aa 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11462,6 +11462,23 @@ class TestOther : public TestFixture { " return i;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("int f(char c) {\n" // #15037 + " int i = (int)c;\n" + " i = 3;\n" + " return i;\n" + "}\n" + "int g(char c) {\n" + " int i = static_cast(c);\n" + " i = 3;\n" + " return i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:7]: style: Redundant initialization for 'i'. The initialized value is overwritten before it is read. [redundantInitialization]\n" + "[test.cpp:2:11]: note: i is initialized\n" + "[test.cpp:3:7]: note: i is overwritten\n" + "[test.cpp:8:8]: style: Redundant initialization for 'i'. The initialized value is overwritten before it is read. [redundantInitialization]\n" + "[test.cpp:7:12]: note: i is initialized\n" + "[test.cpp:8:8]: note: i is overwritten\n", errout_str()); } // cppcheck-suppress unusedPrivateFunction