Fixed false positive unreachableCode when ternary operator is used (#6664)
This commit is contained in:
parent
f637b84192
commit
ee58587706
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue