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() {