Run unreachableCode checking only on executable scopes (#5789)

This commit is contained in:
PKEuS 2014-09-01 11:29:39 +02:00
parent b5e064e737
commit 20a066bb14
2 changed files with 70 additions and 56 deletions

View File

@ -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, "(|[|<"))
@ -1179,6 +1184,7 @@ void CheckOther::checkUnreachableCode()
}
}
}
}
void CheckOther::duplicateBreakError(const Token *tok, bool inconclusive)
{

View File

@ -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());
}