| 41 | //--------------------------------------------------------------------------- |
| 42 | |
| 43 | void CheckExceptionSafetyImpl::destructors() |
| 44 | { |
| 45 | if (!mSettings.severity.isEnabled(Severity::warning)) |
| 46 | return; |
| 47 | |
| 48 | logChecker("CheckExceptionSafety::destructors"); // warning |
| 49 | |
| 50 | const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 51 | |
| 52 | // Perform check.. |
| 53 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 54 | const Function * function = scope->function; |
| 55 | if (!function) |
| 56 | continue; |
| 57 | // only looking for destructors |
| 58 | if (function->type == FunctionType::eDestructor) { |
| 59 | // Inspect this destructor. |
| 60 | for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 61 | // Skip try blocks |
| 62 | if (Token::simpleMatch(tok, "try {")) { |
| 63 | tok = tok->linkAt(1); |
| 64 | } |
| 65 | |
| 66 | // Skip uncaught exceptions |
| 67 | else if (Token::simpleMatch(tok, "if ( ! std :: uncaught_exception ( ) ) {")) { |
| 68 | tok = tok->linkAt(1); // end of if ( ... ) |
| 69 | tok = tok->linkAt(1); // end of { ... } |
| 70 | } |
| 71 | // throw found within a destructor |
| 72 | else if (tok->str() == "throw" && function->isNoExcept()) { |
| 73 | destructorsError(tok, scope->className); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void CheckExceptionSafetyImpl::destructorsError(const Token * const tok, const std::string &className) |
| 82 | { |