From bcd87b05a93d85790a6f4f7082a8be1e9dd34413 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:42:00 +0100 Subject: [PATCH 1/2] Update testother.cpp --- test/testother.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index c2781cbab6c..d49d3e540d2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10613,6 +10613,21 @@ class TestOther : public TestFixture { ASSERT_EQUALS( "[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\n", errout_str()); + + check("std::string f() {\n" // #14534 + " std::string s = \"abc\";\n" + " s = \"def\";\n" + " return s;\n" + "}\n" + "const char* g() {\n" + " const char* p = \"abc\";\n" + " p = \"def\";\n" + " return p;\n" + "}"); + ASSERT_EQUALS( + "[test.cpp:2:19] -> [test.cpp:3:7]: (style) Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\n" + "[test.cpp:7:19] -> [test.cpp:8:7]: (style) Redundant initialization for 'p'. The initialized value is overwritten before it is read. [redundantInitialization]\n", + errout_str()); } void redundantVarAssignment_struct() { From 50b1769e9adf0d20958ef7f5d60510a7aa3f9bf1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:42:52 +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 c4c4cf049b2..ce42524f02d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -631,7 +631,7 @@ void CheckOther::checkRedundantAssignment() [&](const Token *rhs) { if (Token::simpleMatch(rhs, "{ 0 }")) return ChildrenToVisit::none; - if (Token::Match(rhs, "%str%|%num%|%name%") && !rhs->varId()) + if (Token::Match(rhs, "%num%|%name%") && !rhs->varId()) return ChildrenToVisit::none; if (Token::Match(rhs, ":: %name%") && rhs->hasKnownIntValue()) return ChildrenToVisit::none;