Run unreachableCode checking only on executable scopes (#5789)
This commit is contained in:
parent
b5e064e737
commit
20a066bb14
|
@ -1110,7 +1110,12 @@ void CheckOther::checkUnreachableCode()
|
|||
if (!_settings->isEnabled("style"))
|
||||
return;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
|
||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||
const Token* secondBreak = 0;
|
||||
const Token* labelName = 0;
|
||||
if (tok->link() && Token::Match(tok, "(|[|<"))
|
||||
|
@ -1137,7 +1142,7 @@ void CheckOther::checkUnreachableCode()
|
|||
|
||||
// Statements follow directly, no line between them. (#3383)
|
||||
// TODO: Try to find a better way to avoid false positives due to preprocessor configurations.
|
||||
bool inconclusive = secondBreak && (secondBreak->linenr()-1 > secondBreak->previous()->linenr());
|
||||
bool inconclusive = secondBreak && (secondBreak->linenr() - 1 > secondBreak->previous()->linenr());
|
||||
|
||||
if (secondBreak && (_settings->inconclusive || !inconclusive)) {
|
||||
if (Token::Match(secondBreak, "continue|goto|throw") ||
|
||||
|
@ -1178,6 +1183,7 @@ void CheckOther::checkUnreachableCode()
|
|||
tok = tok->previous(); // Will be advanced again by for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::duplicateBreakError(const Token *tok, bool inconclusive)
|
||||
|
|
|
@ -2983,6 +2983,14 @@ private:
|
|||
" };\n"
|
||||
"}", 0, false, false, false, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5789
|
||||
check("struct per_state_info {\n"
|
||||
" uint64_t enter, exit;\n"
|
||||
" uint64_t events;\n"
|
||||
" per_state_info() : enter(0), exit(0), events(0) {}\n"
|
||||
"};", 0, false, false, false, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue