| 237 | } |
| 238 | |
| 239 | static const Token * functionThrowsRecursive(const Function * function, std::set<const Function *> & recursive) |
| 240 | { |
| 241 | // check for recursion and bail if found |
| 242 | if (!recursive.insert(function).second) |
| 243 | return nullptr; |
| 244 | |
| 245 | if (!function->functionScope) |
| 246 | return nullptr; |
| 247 | |
| 248 | for (const Token *tok = function->functionScope->bodyStart->next(); |
| 249 | tok != function->functionScope->bodyEnd; tok = tok->next()) { |
| 250 | tok = skipUnreachableBranch(tok); |
| 251 | if (Token::simpleMatch(tok, "try {")) |
| 252 | tok = tok->linkAt(1); // skip till start of catch clauses |
| 253 | if (tok->str() == "throw") |
| 254 | return tok; |
| 255 | if (tok->function() && (Token::simpleMatch(tok->astParent(), "(") || |
| 256 | (Token::simpleMatch(tok->astParent(), ".") && Token::simpleMatch(tok->astParent()->astParent(), "(")))) { |
| 257 | const Function * called = tok->function(); |
| 258 | // check if called function has an exception specification |
| 259 | if (called->isThrow() && called->throwArg) |
| 260 | return tok; |
| 261 | if (called->isNoExcept() && called->noexceptArg && |
| 262 | called->noexceptArg->str() != "true") |
| 263 | return tok; |
| 264 | if (functionThrowsRecursive(called, recursive)) |
| 265 | return tok; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return nullptr; |
| 270 | } |
| 271 | |
| 272 | static const Token * functionThrows(const Function * function) |
| 273 | { |
no test coverage detected