@@ -3249,6 +3249,11 @@ std::vector<ValueFlow::Value> getLifetimeObjValues(const Token* tok, bool inconc
32493249
32503250static bool hasUniqueOwnership (const Token* tok)
32513251{
3252+ if (!tok)
3253+ return false ;
3254+ const Variable* var = tok->variable ();
3255+ if (var && var->isArray () && !var->isArgument ())
3256+ return true ;
32523257 if (astIsPointer (tok))
32533258 return false ;
32543259 if (astIsUniqueSmartPointer (tok))
@@ -3263,11 +3268,10 @@ static bool derefShared(const Token* tok)
32633268{
32643269 if (!tok)
32653270 return false ;
3266- if (tok->str () == " . " && tok->originalName () != " -> " ) {
3271+ if (! tok->isUnaryOp ( " * " ) && tok-> str () != " [ " && tok->str () != " . " )
32673272 return false ;
3268- } else if (! tok->isUnaryOp ( " * " ) && tok->str () == " [ " ) {
3273+ if (tok->str () == " . " && tok->originalName () != " -> " )
32693274 return false ;
3270- }
32713275 const Token* ptrTok = tok->astOperand1 ();
32723276 return !hasUniqueOwnership (ptrTok);
32733277}
@@ -3386,10 +3390,8 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
33863390 } else if (Token::Match (tok, " .|::|[" ) || tok->isUnaryOp (" *" )) {
33873391
33883392 const Token *vartok = tok;
3389- if (tok->isUnaryOp (" *" ))
3390- vartok = tok->astOperand1 ();
33913393 while (vartok) {
3392- if (vartok->str () == " [" || vartok->originalName () == " ->" )
3394+ if (vartok->str () == " [" || vartok->originalName () == " ->" || vartok-> isUnaryOp ( " * " ) )
33933395 vartok = vartok->astOperand1 ();
33943396 else if (vartok->str () == " ." || vartok->str () == " ::" )
33953397 vartok = vartok->astOperand2 ();
@@ -3399,10 +3401,7 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
33993401
34003402 if (!vartok)
34013403 return {{tok, std::move (errorPath)}};
3402- const Variable *tokvar = vartok->variable ();
3403- const bool isContainer = astIsContainer (vartok) && !astIsPointer (vartok);
3404- if (!astIsUniqueSmartPointer (vartok) && !isContainer && !(tokvar && tokvar->isArray () && !tokvar->isArgument ()) &&
3405- (Token::Match (vartok->astParent (), " [|*" ) || vartok->astParent ()->originalName () == " ->" )) {
3404+ if (derefShared (vartok->astParent ())) {
34063405 for (const ValueFlow::Value &v : vartok->values ()) {
34073406 if (!v.isLocalLifetimeValue ())
34083407 continue ;
0 commit comments