From 084bc740801f69a965e2a5b962b1bcf8dacddfa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Apr 2021 19:43:51 +0200 Subject: [PATCH] Fixed #8223 (false negative: Statements following return, break, continue, goto or throw will never be executed.) --- lib/checkother.cpp | 3 +-- test/testother.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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"