Fixed #8261 (False positive "Statements following return, break, continue, goto or throw will never be executed.")

This commit is contained in:
Daniel Marjamäki 2018-11-12 06:31:17 +01:00
parent 5bda102897
commit 58882b1f14
2 changed files with 9 additions and 0 deletions

View File

@ -1019,6 +1019,8 @@ void CheckOther::checkUnreachableCode()
else if (Token::Match(tok, "break|continue ;")) else if (Token::Match(tok, "break|continue ;"))
secondBreak = tok->tokAt(2); secondBreak = tok->tokAt(2);
else if (Token::Match(tok, "[;{}:] return|throw")) { else if (Token::Match(tok, "[;{}:] return|throw")) {
if (Token::simpleMatch(tok->astParent(), "?"))
continue;
tok = tok->next(); // tok should point to return or throw tok = tok->next(); // tok should point to return or throw
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(" || tok2->str() == "{") if (tok2->str() == "(" || tok2->str() == "{")

View File

@ -2754,6 +2754,13 @@ private:
" bar();\n" " bar();\n"
"}", nullptr, false, false, false, &settings); "}", nullptr, false, false, false, &settings);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #8261
check("void foo() {\n"
" (beat < 100) ? (void)0 : throw(0);\n"
" bar();\n"
"}", nullptr, false, false, false, &settings);
ASSERT_EQUALS("", errout.str());
} }