Skip to content

Commit

Permalink
Fix #12244 FN: unreachableCode with unconditional scope (danmar#7130)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 25, 2024
1 parent 38201c9 commit dbf1f19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ void CheckOther::checkUnreachableCode()
tok2 = tok2->link();
if (tok2->str() == ";") {
secondBreak = tok2->next();
while (Token::simpleMatch(secondBreak, "}") && secondBreak->scope()->type == Scope::ScopeType::eUnconditional)
secondBreak = secondBreak->next();
break;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5606,6 +5606,15 @@ class TestOther : public TestFixture {
" } while (0);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Statements following 'break' will never be executed.\n", errout_str());

check("void f() {\n" // #12244
" {\n"
" std::cout << \"x\";\n"
" return;\n"
" }\n"
" std::cout << \"y\";\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", errout_str());
}

void redundantContinue() {
Expand Down

0 comments on commit dbf1f19

Please sign in to comment.