Fixed #3858 (Throw exception in destructor BUT inside a try-catch shouldn't be reported)

This commit is contained in:
Daniel Marjamäki 2012-06-17 14:33:18 +02:00
parent 62f92fe253
commit a37c3144ed
2 changed files with 16 additions and 0 deletions

View File

@ -42,6 +42,11 @@ void CheckExceptionSafety::destructors()
if (j->type == Function::eDestructor && j->functionScope) { if (j->type == Function::eDestructor && j->functionScope) {
// Inspect this destructor.. // Inspect this destructor..
for (const Token *tok = j->functionScope->classStart->next(); tok != j->functionScope->classEnd; tok = tok->next()) { 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 // throw found within a destructor
if (tok->str() == "throw") { if (tok->str() == "throw") {
destructorsError(tok); destructorsError(tok);

View File

@ -82,6 +82,17 @@ private:
" throw e;\n" " throw e;\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", "", errout.str()); 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() { void deallocThrow1() {