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

Function functionThrowsRecursive

lib/checkexceptionsafety.cpp:239–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239static 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
272static const Token * functionThrows(const Function * function)
273{

Callers 1

functionThrowsFunction · 0.85

Calls 7

skipUnreachableBranchFunction · 0.85
nextMethod · 0.80
linkAtMethod · 0.80
astParentMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45
functionMethod · 0.45

Tested by

no test coverage detected