@@ -279,36 +279,31 @@ static const Token * isFunctionCall(const Token * nameToken)
279279 * @param tok on the LHS of a function call
280280 * @return opening parenthesis token or nullptr if not a function call
281281 */
282- static const Token * isAnonymousFunctionCall (const Token * tok)
282+ static const Token *isAnonymousFunctionCall (const Token *tok)
283283{
284- // match one of the supported LHS patterns
285- // TODO: check if tok->previous()->isCast(). can't right now because
286- //
287- // auto x = [](void *ptr) { g(ptr) };
288- // void *p = malloc(1);
289- // (x)(p);
290- // ^
291- // the lpar surrounding x has isCast() == true, so checking isCast() would
292- // have false positive leaks, while allowing casts to take ownership of
293- // resources is instead a false negative
294- if (tok->strAt (-1 ) == " (" && !tok->previous ()->isBinaryOp () &&
295- tok->linkAt (-1 ) && !tok->isStandardType ()) {
284+ if (!tok || tok->isStandardType ())
285+ return nullptr ;
286+
287+ auto isLparNotCast = [](const Token *lpar) -> bool {
288+ return !lpar->isCast () && lpar->str () == " (" ;
289+ };
290+
291+ // function pointer or lambda
292+ if (isLparNotCast (tok->previous ())) {
296293 tok = tok->linkAt (-1 )->next ();
297- } else if (! tok->isStandardType () && tok->isName () &&
298- tok-> strAt ( 1 ) == " ( " ) {
294+ } else if (tok->isName () && isLparNotCast ( tok->next ())) {
295+ // call to result of a function
299296 tok = tok->linkAt (1 )->next ();
300297 } else {
301298 return nullptr ;
302299 }
303300
304- // skip over potential template arguments
301+ // < could be a less than, not a template operator
305302 if (tok->link () && tok->str () == " <" )
306303 tok = tok->link ()->next ();
307304
308- // return the opening parenthesis
309- if (tok && tok->link () && !tok->isCast () && tok->str () == " (" )
305+ if (isLparNotCast (tok))
310306 return tok;
311-
312307 return nullptr ;
313308}
314309
0 commit comments