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

Method unhandledExceptionSpecification

lib/checkexceptionsafety.cpp:329–357  ·  view source on GitHub ↗

-------------------------------------------------------------------------- void func() { functionWithExceptionSpecification(); } --------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

327// void func() { functionWithExceptionSpecification(); }
328//--------------------------------------------------------------------------
329void CheckExceptionSafetyImpl::unhandledExceptionSpecification()
330{
331 if ((!mSettings.severity.isEnabled(Severity::style) || !mSettings.certainty.isEnabled(Certainty::inconclusive)) &&
332 !mSettings.isPremiumEnabled("unhandledExceptionSpecification"))
333 return;
334
335 logChecker("CheckExceptionSafety::unhandledExceptionSpecification"); // style,inconclusive
336
337 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
338
339 for (const Scope * scope : symbolDatabase->functionScopes) {
340 // only check functions without exception specification
341 if (scope->function && !scope->function->isThrow() && !mSettings.library.isentrypoint(scope->className)) {
342 for (const Token *tok = scope->function->functionScope->bodyStart->next();
343 tok != scope->function->functionScope->bodyEnd; tok = tok->next()) {
344 if (tok->str() == "try")
345 break;
346 if (tok->function()) {
347 const Function * called = tok->function();
348 // check if called function has an exception specification
349 if (called->isThrow() && called->throwArg) {
350 unhandledExceptionSpecificationError(tok, called->tokenDef, scope->function->name());
351 break;
352 }
353 }
354 }
355 }
356 }
357}
358
359void CheckExceptionSafetyImpl::unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname)
360{

Callers 1

runChecksMethod · 0.80

Calls 7

isPremiumEnabledMethod · 0.80
isentrypointMethod · 0.80
nextMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45
functionMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected