Skip to content

Commit 32a37f4

Browse files
Follow-up to #13478: Fix FP, remove redundant statement (danmar#7138)
1 parent 1599f85 commit 32a37f4

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/checkother.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,9 @@ void CheckOther::checkUnreachableCode()
907907
tok->str() == "break") {
908908
while (Token::simpleMatch(secondBreak, "{") && secondBreak->scope()->type == Scope::ScopeType::eUnconditional)
909909
secondBreak = secondBreak->next();
910-
if (Token::Match(secondBreak, "%name% :"))
911-
continue;
912910
}
913-
if (Token::simpleMatch(secondBreak, "; }"))
914-
continue;
911+
while (Token::simpleMatch(secondBreak, ";"))
912+
secondBreak = secondBreak->next();
915913

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

test/testother.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5624,6 +5624,31 @@ class TestOther : public TestFixture {
56245624
" std::cout << \"y\";\n"
56255625
"}\n");
56265626
ASSERT_EQUALS("[test.cpp:6]: (style) Statements following noreturn function 'exit()' will never be executed.\n", errout_str());
5627+
5628+
check("int f() {\n" // #13475
5629+
" { return 0; };\n"
5630+
"}\n");
5631+
ASSERT_EQUALS("", errout_str());
5632+
5633+
check("int f(int i) {\n" // #13478
5634+
" int x = 0;\n"
5635+
" switch (i) {\n"
5636+
" { case 0: x = 5; break; }\n"
5637+
" { case 1: x = 7; break; }\n"
5638+
" }\n"
5639+
" return x;\n"
5640+
"}\n");
5641+
ASSERT_EQUALS("", errout_str());
5642+
5643+
check("int f(int c) {\n"
5644+
" switch (c) {\n"
5645+
" case '\\n':\n"
5646+
" { return 1; };\n"
5647+
" default:\n"
5648+
" { return c; };\n"
5649+
" }\n"
5650+
"}\n");
5651+
ASSERT_EQUALS("", errout_str());
56275652
}
56285653

56295654
void redundantContinue() {

0 commit comments

Comments
 (0)