Hande try and do in initialization list usage check (#3823)

This commit is contained in:
PKEuS 2012-05-22 01:35:56 -07:00
parent e8dfe2407a
commit f5ef6f255e
2 changed files with 8 additions and 0 deletions

View File

@ -513,6 +513,8 @@ void CheckClass::initializationListUsage()
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%var% (")) // Assignments might depend on this function call or if/for/while/switch statment from now on.
break;
if (Token::Match(tok, "try|do {"))
break;
if (tok->varId() && Token::Match(tok, "%var% = %any%")) {
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
if (var && var->scope() == owner) {

View File

@ -5159,6 +5159,12 @@ private:
" Fred() : b(5) { a = b; }\n" // Don't issue a message here: You actually could move it to the initalization list, but it would cause problems if you change the order of the variable declarations.
"};");
ASSERT_EQUALS("", errout.str());
checkInitializationListUsage("class Fred {\n"
" int a;\n"
" Fred() { try { a = new int; } catch(...) {} }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
};