Hande try and do in initialization list usage check (#3823)
This commit is contained in:
parent
e8dfe2407a
commit
f5ef6f255e
|
@ -513,6 +513,8 @@ void CheckClass::initializationListUsage()
|
||||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
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.
|
if (Token::Match(tok, "%var% (")) // Assignments might depend on this function call or if/for/while/switch statment from now on.
|
||||||
break;
|
break;
|
||||||
|
if (Token::Match(tok, "try|do {"))
|
||||||
|
break;
|
||||||
if (tok->varId() && Token::Match(tok, "%var% = %any%")) {
|
if (tok->varId() && Token::Match(tok, "%var% = %any%")) {
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
|
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
|
||||||
if (var && var->scope() == owner) {
|
if (var && var->scope() == owner) {
|
||||||
|
|
|
@ -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.
|
" 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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkInitializationListUsage("class Fred {\n"
|
||||||
|
" int a;\n"
|
||||||
|
" Fred() { try { a = new int; } catch(...) {} }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue