Skip to content

Commit 5aa8739

Browse files
Fix #14566 FP variableScope (variable used in loop) (danmar#8296)
1 parent 26f1287 commit 5aa8739

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ static bool isOnlyUsedInCurrentScope(const Variable* var, const Token *tok, cons
13371337
return true;
13381338
if (tok->scope()->type == ScopeType::eSwitch)
13391339
return false;
1340-
return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", scope->bodyEnd, var->declarationId());
1340+
return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", var->scope()->bodyEnd, var->declarationId());
13411341
}
13421342

13431343
bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& used) const

test/testother.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,20 @@ class TestOther : public TestFixture {
20262026
" }\n"
20272027
"}\n");
20282028
ASSERT_EQUALS("", errout_str());
2029+
2030+
check("void f(int& r) {\n" // #14566
2031+
" int i = 0;\n"
2032+
" while (g()) {\n"
2033+
" {\n"
2034+
" if (g()) {\n"
2035+
" i = 0;"
2036+
" std::swap(i, r);\n"
2037+
" }\n"
2038+
" }\n"
2039+
" }\n"
2040+
" use(i);"
2041+
"}\n");
2042+
ASSERT_EQUALS("", errout_str());
20292043
}
20302044

20312045
#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)

0 commit comments

Comments
 (0)