-------------------------------------------------------------------------- 7.6.18.4 If no exception is presently being handled, evaluating a throw-expression with no operand calls std::terminate(). --------------------------------------------------------------------------
| 370 | // 7.6.18.4 If no exception is presently being handled, evaluating a throw-expression with no operand calls std::terminate(). |
| 371 | //-------------------------------------------------------------------------- |
| 372 | void 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 | |
| 403 | void CheckExceptionSafetyImpl::rethrowNoCurrentExceptionError(const Token *tok) |
| 404 | { |
no test coverage detected