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

Method checkLibraryMatchFunctions

lib/checkfunctions.cpp:628–701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626//---------------------------------------------------------------------------
627
628void CheckFunctionsImpl::checkLibraryMatchFunctions()
629{
630 if (!mSettings.checkLibrary)
631 return;
632
633 bool insideNew = false;
634 for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
635 if (!tok->scope() || !tok->scope()->isExecutable())
636 continue;
637
638 // skip uninstantiated templates
639 if (tok == tok->scope()->bodyStart && tok->scope()->function && tok->scope()->function->templateDef) {
640 tok = tok->link();
641 continue;
642 }
643
644 if (tok->str() == "new")
645 insideNew = true;
646 else if (tok->str() == ";")
647 insideNew = false;
648 else if (insideNew)
649 continue;
650
651 if (tok->isKeyword() || !Token::Match(tok, "%name% ("))
652 continue;
653
654 if (tok->varId() != 0 || tok->type() || tok->isStandardType())
655 continue;
656
657 if (tok->linkAt(1)->strAt(1) == "(")
658 continue;
659
660 if (tok->function())
661 continue;
662
663 if (Token::simpleMatch(tok->astTop(), "throw"))
664 continue;
665
666 if (Token::simpleMatch(tok->astParent(), ".")) {
667 const Token* contTok = tok->astParent()->astOperand1();
668 if (astContainerAction(contTok, mSettings.library) != Library::Container::Action::NO_ACTION)
669 continue;
670 if (astContainerYield(contTok, mSettings.library) != Library::Container::Yield::NO_YIELD)
671 continue;
672 }
673
674 if (!mSettings.library.isNotLibraryFunction(tok))
675 continue;
676
677 const std::string &functionName = mSettings.library.getFunctionName(tok);
678 if (functionName.empty())
679 continue;
680
681 if (mSettings.library.functions().find(functionName) != mSettings.library.functions().end())
682 continue;
683
684 if (mSettings.library.podtype(tok->expressionString()))
685 continue;

Callers 1

runChecksMethod · 0.45

Calls 15

astContainerActionFunction · 0.85
astContainerYieldFunction · 0.85
nextMethod · 0.80
scopeMethod · 0.80
typeMethod · 0.80
linkAtMethod · 0.80
astTopMethod · 0.80
astParentMethod · 0.80
astOperand1Method · 0.80
isNotLibraryFunctionMethod · 0.80
getFunctionNameMethod · 0.80
getTypeCheckMethod · 0.80

Tested by

no test coverage detected