MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / destructors

Method destructors

lib/checkexceptionsafety.cpp:43–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41//---------------------------------------------------------------------------
42
43void 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
81void CheckExceptionSafetyImpl::destructorsError(const Token * const tok, const std::string &className)
82{

Callers 1

runChecksMethod · 0.45

Calls 5

nextMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
isEnabledMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected