Skip to content

Commit 6241809

Browse files
committed
Fix
1 parent c6daf43 commit 6241809

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,8 @@ static bool isOnlyUsedInCurrentScope(const Variable* var, const Token *tok, cons
13351335
{
13361336
if (tok->scope() == scope)
13371337
return true;
1338+
if (tok->scope()->type == ScopeType::eSwitch)
1339+
return false;
13381340
return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", scope->bodyEnd, var->declarationId());
13391341
}
13401342

test/testother.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ class TestOther : public TestFixture {
19861986
}
19871987

19881988
void varScope46() {
1989-
check("void f() {\n"
1989+
check("void f() {\n" // #7091
19901990
" int y1;\n"
19911991
" for (int i = 0; i < 3; ++i) {\n"
19921992
" for(int j = 0; j < 3; ++j) {\n"
@@ -1997,6 +1997,24 @@ class TestOther : public TestFixture {
19971997
"}\n");
19981998
ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'y1' can be reduced. [variableScope]\n",
19991999
errout_str());
2000+
2001+
check("bool f() {\n"
2002+
"bool b = false;\n"
2003+
"do {\n"
2004+
" switch (g()) {\n"
2005+
" case 0:\n"
2006+
" b = true;\n"
2007+
" break;\n"
2008+
" case 1:\n"
2009+
" return b;\n"
2010+
" break;\n"
2011+
" default:\n"
2012+
" break;\n"
2013+
" }\n"
2014+
"}\n"
2015+
"while (true);\n"
2016+
"}\n");
2017+
ASSERT_EQUALS("", errout_str());
20002018
}
20012019

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

0 commit comments

Comments
 (0)