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

Function findConstructor

lib/valueflow.cpp:2616–2641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2614}
2615
2616static const Function* findConstructor(const Scope* scope, const Token* tok, const std::vector<const Token*>& args)
2617{
2618 if (!tok)
2619 return nullptr;
2620 const Function* f = tok->function();
2621 if (!f && tok->astOperand1())
2622 f = tok->astOperand1()->function();
2623 // Search for a constructor
2624 if (!f || !f->isConstructor()) {
2625 f = nullptr;
2626 std::vector<const Function*> candidates;
2627 for (const Function& function : scope->functionList) {
2628 if (function.minArgCount() > args.size())
2629 continue;
2630 if (!function.isConstructor())
2631 continue;
2632 candidates.push_back(&function);
2633 }
2634 // TODO: Narrow the candidates
2635 if (candidates.size() == 1)
2636 f = candidates.front();
2637 }
2638 if (!f)
2639 return nullptr;
2640 return f;
2641}
2642
2643static void valueFlowLifetimeClassConstructor(Token* tok,
2644 const Type* t,

Callers 1

Calls 5

astOperand1Method · 0.80
frontMethod · 0.80
functionMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected