Refactor to use derefShared (#4220)
This commit is contained in:
parent
2a0b2f538e
commit
e6fdcb9de2
|
@ -3249,6 +3249,11 @@ std::vector<ValueFlow::Value> getLifetimeObjValues(const Token* tok, bool inconc
|
||||||
|
|
||||||
static bool hasUniqueOwnership(const Token* tok)
|
static bool hasUniqueOwnership(const Token* tok)
|
||||||
{
|
{
|
||||||
|
if (!tok)
|
||||||
|
return false;
|
||||||
|
const Variable* var = tok->variable();
|
||||||
|
if (var && var->isArray() && !var->isArgument())
|
||||||
|
return true;
|
||||||
if (astIsPointer(tok))
|
if (astIsPointer(tok))
|
||||||
return false;
|
return false;
|
||||||
if (astIsUniqueSmartPointer(tok))
|
if (astIsUniqueSmartPointer(tok))
|
||||||
|
@ -3263,11 +3268,10 @@ static bool derefShared(const Token* tok)
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return false;
|
return false;
|
||||||
if (tok->str() == "." && tok->originalName() != "->") {
|
if (!tok->isUnaryOp("*") && tok->str() != "[" && tok->str() != ".")
|
||||||
return false;
|
return false;
|
||||||
} else if (!tok->isUnaryOp("*") && tok->str() == "[") {
|
if (tok->str() == "." && tok->originalName() != "->")
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
const Token* ptrTok = tok->astOperand1();
|
const Token* ptrTok = tok->astOperand1();
|
||||||
return !hasUniqueOwnership(ptrTok);
|
return !hasUniqueOwnership(ptrTok);
|
||||||
}
|
}
|
||||||
|
@ -3386,10 +3390,8 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
} else if (Token::Match(tok, ".|::|[") || tok->isUnaryOp("*")) {
|
} else if (Token::Match(tok, ".|::|[") || tok->isUnaryOp("*")) {
|
||||||
|
|
||||||
const Token *vartok = tok;
|
const Token *vartok = tok;
|
||||||
if (tok->isUnaryOp("*"))
|
|
||||||
vartok = tok->astOperand1();
|
|
||||||
while (vartok) {
|
while (vartok) {
|
||||||
if (vartok->str() == "[" || vartok->originalName() == "->")
|
if (vartok->str() == "[" || vartok->originalName() == "->" || vartok->isUnaryOp("*"))
|
||||||
vartok = vartok->astOperand1();
|
vartok = vartok->astOperand1();
|
||||||
else if (vartok->str() == "." || vartok->str() == "::")
|
else if (vartok->str() == "." || vartok->str() == "::")
|
||||||
vartok = vartok->astOperand2();
|
vartok = vartok->astOperand2();
|
||||||
|
@ -3399,10 +3401,7 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
|
|
||||||
if (!vartok)
|
if (!vartok)
|
||||||
return {{tok, std::move(errorPath)}};
|
return {{tok, std::move(errorPath)}};
|
||||||
const Variable *tokvar = vartok->variable();
|
if (derefShared(vartok->astParent())) {
|
||||||
const bool isContainer = astIsContainer(vartok) && !astIsPointer(vartok);
|
|
||||||
if (!astIsUniqueSmartPointer(vartok) && !isContainer && !(tokvar && tokvar->isArray() && !tokvar->isArgument()) &&
|
|
||||||
(Token::Match(vartok->astParent(), "[|*") || vartok->astParent()->originalName() == "->")) {
|
|
||||||
for (const ValueFlow::Value &v : vartok->values()) {
|
for (const ValueFlow::Value &v : vartok->values()) {
|
||||||
if (!v.isLocalLifetimeValue())
|
if (!v.isLocalLifetimeValue())
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue