File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -903,7 +903,14 @@ void CheckOther::checkUnreachableCode()
903903 }
904904 while (Token::simpleMatch (secondBreak, " }" ) && secondBreak->scope ()->type == Scope::ScopeType::eUnconditional)
905905 secondBreak = secondBreak->next ();
906- if (Token::simpleMatch (secondBreak, " ;" ))
906+ if (secondBreak && secondBreak->scope ()->nestedIn && secondBreak->scope ()->nestedIn ->type == Scope::ScopeType::eSwitch &&
907+ tok->str () == " break" ) {
908+ while (Token::simpleMatch (secondBreak, " {" ) && secondBreak->scope ()->type == Scope::ScopeType::eUnconditional)
909+ secondBreak = secondBreak->next ();
910+ if (Token::Match (secondBreak, " %name% :" ))
911+ continue ;
912+ }
913+ if (Token::simpleMatch (secondBreak, " ; }" ))
907914 continue ;
908915
909916 // Statements follow directly, no line between them. (#3383)
Original file line number Diff line number Diff line change @@ -5649,6 +5649,16 @@ class TestOther : public TestFixture {
56495649 " { return 0; };\n "
56505650 " }\n " );
56515651 ASSERT_EQUALS (" " , errout_str ());
5652+
5653+ check (" int f(int i) {\n " // #13478
5654+ " int x = 0;\n "
5655+ " switch (i) {\n "
5656+ " { case 0: x = 5; break; }\n "
5657+ " { case 1: x = 7; break; }\n "
5658+ " }\n "
5659+ " return x;\n "
5660+ " }\n " );
5661+ ASSERT_EQUALS (" " , errout_str ());
56525662 }
56535663
56545664
You can’t perform that action at this time.
0 commit comments