From 7edfff9db11341a722aa0fead3b80d99816c95af Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:15:25 +0100 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 32dedf8f374..bbc6bdb90d0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1337,7 +1337,7 @@ static bool isOnlyUsedInCurrentScope(const Variable* var, const Token *tok, cons return true; if (tok->scope()->type == ScopeType::eSwitch) return false; - return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", scope->bodyEnd, var->declarationId()); + return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", var->scope()->bodyEnd, var->declarationId()); } bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& used) const From 1f0d5d8633227ba0754cd0123e243ab2077e7e17 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:20:15 +0100 Subject: [PATCH 2/2] Update testother.cpp --- test/testother.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 53f14c2a31d..88c83eba4b1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2026,6 +2026,20 @@ class TestOther : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(int& r) {\n" // #14566 + " int i = 0;\n" + " while (g()) {\n" + " {\n" + " if (g()) {\n" + " i = 0;" + " std::swap(i, r);\n" + " }\n" + " }\n" + " }\n" + " use(i);" + "}\n"); + ASSERT_EQUALS("", errout_str()); } #define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)