Skip to content

Commit dbf1f19

Browse files
Fix #12244 FN: unreachableCode with unconditional scope (danmar#7130)
1 parent 38201c9 commit dbf1f19

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ void CheckOther::checkUnreachableCode()
887887
tok2 = tok2->link();
888888
if (tok2->str() == ";") {
889889
secondBreak = tok2->next();
890+
while (Token::simpleMatch(secondBreak, "}") && secondBreak->scope()->type == Scope::ScopeType::eUnconditional)
891+
secondBreak = secondBreak->next();
890892
break;
891893
}
892894
}

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5606,6 +5606,15 @@ class TestOther : public TestFixture {
56065606
" } while (0);\n"
56075607
"}\n");
56085608
ASSERT_EQUALS("[test.cpp:4]: (style) Statements following 'break' will never be executed.\n", errout_str());
5609+
5610+
check("void f() {\n" // #12244
5611+
" {\n"
5612+
" std::cout << \"x\";\n"
5613+
" return;\n"
5614+
" }\n"
5615+
" std::cout << \"y\";\n"
5616+
"}\n");
5617+
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", errout_str());
56095618
}
56105619

56115620
void redundantContinue() {

0 commit comments

Comments
 (0)