Fixed #8261 (False positive "Statements following return, break, continue, goto or throw will never be executed.")
This commit is contained in:
parent
5bda102897
commit
58882b1f14
|
@ -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() == "{")
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue