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 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__)