Skip to content

Commit e427162

Browse files
Followup to #12244: FN unreachableCode (danmar#7131)
1 parent dbf1f19 commit e427162

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,6 @@ 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();
892890
break;
893891
}
894892
}
@@ -903,6 +901,8 @@ void CheckOther::checkUnreachableCode()
903901
continue;
904902
}
905903
}
904+
while (Token::simpleMatch(secondBreak, "}") && secondBreak->scope()->type == Scope::ScopeType::eUnconditional)
905+
secondBreak = secondBreak->next();
906906

907907
// Statements follow directly, no line between them. (#3383)
908908
// TODO: Try to find a better way to avoid false positives due to preprocessor configurations.

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,15 @@ class TestOther : public TestFixture {
56155615
" std::cout << \"y\";\n"
56165616
"}\n");
56175617
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", errout_str());
5618+
5619+
check("void f() {\n"
5620+
" {\n"
5621+
" std::cout << \"x\";\n"
5622+
" exit(1);\n"
5623+
" }\n"
5624+
" std::cout << \"y\";\n"
5625+
"}\n");
5626+
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following noreturn function 'exit()' will never be executed.\n", errout_str());
56185627
}
56195628

56205629
void redundantContinue() {

0 commit comments

Comments
 (0)