diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 60de62655..db3bb41ef 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -809,8 +809,7 @@ void CheckOther::checkUnreachableCode() const bool inconclusive = secondBreak && (secondBreak->linenr() - 1 > secondBreak->previous()->linenr()); if (secondBreak && (printInconclusive || !inconclusive)) { - if (Token::Match(secondBreak, "continue|goto|throw") || - (secondBreak->str() == "return" && (tok->str() == "return" || secondBreak->strAt(1) == ";"))) { // return with value after statements like throw can be necessary to make a function compile + if (Token::Match(secondBreak, "continue|goto|throw|return")) { duplicateBreakError(secondBreak, inconclusive); tok = Token::findmatch(secondBreak, "[}:]"); } else if (secondBreak->str() == "break") { // break inside switch as second break statement should not issue a warning diff --git a/test/testother.cpp b/test/testother.cpp index 89e9e3962..898297e77 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3549,7 +3549,7 @@ private: " throw 0;\n" " return 1;\n" "}", nullptr, false, false, false); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("void foo() {\n" " throw 0;\n"