From a37c3144edf0a9d4d1cd8766b609bb7de9e816b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 Jun 2012 14:33:18 +0200 Subject: [PATCH] Fixed #3858 (Throw exception in destructor BUT inside a try-catch shouldn't be reported) --- lib/checkexceptionsafety.cpp | 5 +++++ test/testexceptionsafety.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 52fe66d69..c163fbc75 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -42,6 +42,11 @@ void CheckExceptionSafety::destructors() if (j->type == Function::eDestructor && j->functionScope) { // Inspect this destructor.. for (const Token *tok = j->functionScope->classStart->next(); tok != j->functionScope->classEnd; tok = tok->next()) { + // Skip try blocks + if (Token::simpleMatch(tok, "try {")) { + tok = tok->next()->link(); + } + // throw found within a destructor if (tok->str() == "throw") { destructorsError(tok); diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 185aa08fb..ba35483db 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -82,6 +82,17 @@ private: " throw e;\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", "", errout.str()); + + // #3858 - throwing exception in try block in destructor + check("class x {\n" + " ~x() {\n" + " try {\n" + " throw e;\n" + " } catch (...) {\n" + " }\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void deallocThrow1() {