Skip to content

Commit

Permalink
Followup to #12244: FN unreachableCode (danmar#7131)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 25, 2024
1 parent dbf1f19 commit e427162
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,6 @@ 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 All @@ -903,6 +901,8 @@ void CheckOther::checkUnreachableCode()
continue;
}
}
while (Token::simpleMatch(secondBreak, "}") && secondBreak->scope()->type == Scope::ScopeType::eUnconditional)
secondBreak = secondBreak->next();

// Statements follow directly, no line between them. (#3383)
// TODO: Try to find a better way to avoid false positives due to preprocessor configurations.
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5615,6 +5615,15 @@ class TestOther : public TestFixture {
" std::cout << \"y\";\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", errout_str());

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

void redundantContinue() {
Expand Down

0 comments on commit e427162

Please sign in to comment.