Fixed #8223 (false negative: Statements following return, break, continue, goto or throw will never be executed.)
This commit is contained in:
parent
518fb01553
commit
084bc74080
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue