Fixed false positive unreachableCode when ternary operator is used (#6664)

This commit is contained in:
PKEuS 2015-10-26 08:29:43 +01:00
parent f637b84192
commit ee58587706
2 changed files with 14 additions and 1 deletions

View File

@ -1021,7 +1021,7 @@ void CheckOther::checkUnreachableCode()
} else if (Token::Match(tok, "goto %any% ;")) {
secondBreak = tok->tokAt(3);
labelName = tok->next();
} else if (Token::Match(tok, "%name% (") && _settings->library.isnoreturn(tok)) {
} else if (Token::Match(tok, "%name% (") && _settings->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);
}

View File

@ -3147,6 +3147,19 @@ private:
" per_state_info() : enter(0), exit(0), events(0) {}\n"
"};", nullptr, false, false, false);
ASSERT_EQUALS("", errout.str());
// #6664
check("void foo() {\n"
" (beat < 100) ? (void)0 : exit(0);\n"
" bar();\n"
"}", nullptr, false, false, false, &settings);
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" (beat < 100) ? exit(0) : (void)0;\n"
" bar();\n"
"}", nullptr, false, false, false, &settings);
ASSERT_EQUALS("", errout.str());
}