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

Method rethrowNoCurrentException

lib/checkexceptionsafety.cpp:372–401  ·  view source on GitHub ↗

-------------------------------------------------------------------------- 7.6.18.4 If no exception is presently being handled, evaluating a throw-expression with no operand calls std​::​​terminate(). --------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

370// 7.6.18.4 If no exception is presently being handled, evaluating a throw-expression with no operand calls std​::​​terminate().
371//--------------------------------------------------------------------------
372void CheckExceptionSafetyImpl::rethrowNoCurrentException()
373{
374 logChecker("CheckExceptionSafety::rethrowNoCurrentException");
375 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
376 for (const Scope * scope : symbolDatabase->functionScopes) {
377 const Function* function = scope->function;
378 if (!function)
379 continue;
380
381 // Rethrow can be used in 'exception dispatcher' idiom which is FP in such case
382 // https://isocpp.org/wiki/faq/exceptions#throw-without-an-object
383 // We check the beginning of the function with idiom pattern
384 if (Token::simpleMatch(function->functionScope->bodyStart->next(), "try { throw ; } catch ("))
385 continue;
386
387 for (const Token *tok = function->functionScope->bodyStart->next();
388 tok != function->functionScope->bodyEnd; tok = tok->next()) {
389 if (Token::simpleMatch(tok, "catch (")) {
390 tok = tok->linkAt(1); // skip catch argument
391 if (Token::simpleMatch(tok, ") {"))
392 tok = tok->linkAt(1); // skip catch scope
393 else
394 break;
395 }
396 if (Token::simpleMatch(tok, "throw ;")) {
397 rethrowNoCurrentExceptionError(tok);
398 }
399 }
400 }
401}
402
403void CheckExceptionSafetyImpl::rethrowNoCurrentExceptionError(const Token *tok)
404{

Callers 1

runChecksMethod · 0.80

Calls 3

nextMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70

Tested by

no test coverage detected