diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f51318190..4f6ef1c70 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 8f61295e0..0f6663e38 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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()); } };