duplicateBreak; Allow extra return that clarifies for tool(s) that function does not continue

This commit is contained in:
Daniel Marjamäki 2021-06-29 11:16:54 +02:00
parent a2cb9f17c1
commit 1783fd1bba
2 changed files with 10 additions and 0 deletions

View File

@ -802,6 +802,10 @@ void CheckOther::checkUnreachableCode()
} else if (Token::Match(tok, "%name% (") && mSettings->library.isnoreturn(tok) && !Token::Match(tok->next()->astParent(), "?|:")) {
if ((!tok->function() || (tok->function()->token != tok && tok->function()->tokenDef != tok)) && tok->linkAt(1)->strAt(1) != "{")
secondBreak = tok->linkAt(1)->tokAt(2);
if (Token::simpleMatch(secondBreak, "return")) {
// clarification for tools that function returns
continue;
}
}
// Statements follow directly, no line between them. (#3383)

View File

@ -3772,6 +3772,12 @@ private:
" bar();\n"
"}", nullptr, false, false, false, false, &settings), InternalError);
//ASSERT_EQUALS("", errout.str());
check("int foo() {\n"
" exit(0);\n"
" return 1;\n" // <- clarify for tools that function does not continue..
"}");
ASSERT_EQUALS("", errout.str());
}