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

Function valueFlowLifetimeConstructor

lib/valueflow.cpp:2723–2787  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2721}
2722
2723static void valueFlowLifetimeConstructor(Token* tok, const TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings)
2724{
2725 if (!Token::Match(tok, "(|{"))
2726 return;
2727 if (isScope(tok))
2728 return;
2729 std::vector<ValueType> vts;
2730 if (tok->valueType()) {
2731 vts = {*tok->valueType()};
2732 } else if (Token::Match(tok->previous(), "%var% {|(") && isVariableDecl(tok->previous()) &&
2733 tok->previous()->valueType()) {
2734 vts = {*tok->previous()->valueType()};
2735 } else if (Token::simpleMatch(tok, "{") && !Token::Match(tok->previous(), "%name%")) {
2736 vts = getParentValueTypes(tok, settings);
2737 }
2738
2739 for (const ValueType& vt : vts) {
2740 if (vt.pointer > 0) {
2741 std::vector<const Token*> args = getArguments(tok);
2742 LifetimeStore::forEach(tokenlist,
2743 errorLogger,
2744 settings,
2745 args,
2746 "Passed to initializer list.",
2747 ValueFlow::Value::LifetimeKind::SubObject,
2748 [&](LifetimeStore& ls) {
2749 ls.byVal(tok, tokenlist, errorLogger, settings);
2750 });
2751 } else if (vt.container && vt.type == ValueType::CONTAINER) {
2752 std::vector<const Token*> args = getArguments(tok);
2753 if (args.size() == 1 && vt.container->view && astIsContainerOwned(args.front())) {
2754 LifetimeStore{args.front(), "Passed to container view.", ValueFlow::Value::LifetimeKind::SubObject}
2755 .byRef(tok, tokenlist, errorLogger, settings);
2756 } else if (args.size() == 2 && (astIsIterator(args[0]) || astIsIterator(args[1]))) {
2757 LifetimeStore::forEach(
2758 tokenlist,
2759 errorLogger,
2760 settings,
2761 args,
2762 "Passed to initializer list.",
2763 ValueFlow::Value::LifetimeKind::SubObject,
2764 [&](const LifetimeStore& ls) {
2765 ls.byDerefCopy(tok, tokenlist, errorLogger, settings);
2766 });
2767 } else if (vt.container->hasInitializerListConstructor) {
2768 LifetimeStore::forEach(tokenlist,
2769 errorLogger,
2770 settings,
2771 args,
2772 "Passed to initializer list.",
2773 ValueFlow::Value::LifetimeKind::SubObject,
2774 [&](LifetimeStore& ls) {
2775 ls.byVal(tok, tokenlist, errorLogger, settings);
2776 });
2777 }
2778 } else {
2779 const Type* t = nullptr;
2780 if (vt.typeScope && vt.typeScope->definedType)

Callers 3

valueFlowForwardLifetimeFunction · 0.85
valueFlowLifetimeFunction · 0.85

Calls 13

isScopeFunction · 0.85
isVariableDeclFunction · 0.85
getParentValueTypesFunction · 0.85
astIsContainerOwnedFunction · 0.85
astIsIteratorFunction · 0.85
byValMethod · 0.80
frontMethod · 0.80
byRefMethod · 0.80
byDerefCopyMethod · 0.80
simpleMatchFunction · 0.70
getArgumentsFunction · 0.70

Tested by

no test coverage detected