diff --git a/lib/checkother.cpp b/lib/checkother.cpp index eb4b0e0ea98..42ca0f0d2ba 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; } } diff --git a/test/testother.cpp b/test/testother.cpp index 6e7b2ec04b8..1caa442ffa8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {