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

Function getInnerLifetime

lib/checkstl.cpp:1070–1104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1068}
1069
1070static const ValueFlow::Value* getInnerLifetime(const Token* tok,
1071 nonneg int id,
1072 ErrorPath* errorPath = nullptr,
1073 int depth = 4)
1074{
1075 if (depth < 0)
1076 return nullptr;
1077 if (!tok)
1078 return nullptr;
1079 for (const ValueFlow::Value& val : tok->values()) {
1080 if (!val.isLocalLifetimeValue())
1081 continue;
1082 if (contains({ValueFlow::Value::LifetimeKind::Address,
1083 ValueFlow::Value::LifetimeKind::SubObject,
1084 ValueFlow::Value::LifetimeKind::Lambda},
1085 val.lifetimeKind)) {
1086 if (val.isInconclusive())
1087 return nullptr;
1088 if (val.capturetok)
1089 if (const ValueFlow::Value* v = getInnerLifetime(val.capturetok, id, errorPath, depth - 1))
1090 return v;
1091 if (errorPath)
1092 errorPath->insert(errorPath->end(), val.errorPath.cbegin(), val.errorPath.cend());
1093 if (const ValueFlow::Value* v = getInnerLifetime(val.tokvalue, id, errorPath, depth - 1))
1094 return v;
1095 continue;
1096 }
1097 if (!val.tokvalue->variable())
1098 continue;
1099 if (val.tokvalue->varId() != id)
1100 continue;
1101 return &val;
1102 }
1103 return nullptr;
1104}
1105
1106static const Token* endOfExpression(const Token* tok)
1107{

Callers 1

invalidContainerMethod · 0.85

Calls 4

containsFunction · 0.85
variableMethod · 0.80
isInconclusiveMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected