From f5ef6f255e3ed582f041c0792561cf769cb0b84f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 22 May 2012 01:35:56 -0700 Subject: [PATCH] Hande try and do in initialization list usage check (#3823) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 6 ++++++ 2 files changed, 8 insertions(+) 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()); } };