@@ -2435,6 +2435,31 @@ static bool isArray(const Token* tok)
24352435 return false ;
24362436}
24372437
2438+ static bool isMutableExpression (const Token* tok)
2439+ {
2440+ if (!tok)
2441+ return false ;
2442+ if (tok->isLiteral () || tok->isKeyword () || tok->isStandardType () || tok->isEnumerator ())
2443+ return false ;
2444+ if (Token::Match (tok, " ,|;|:|]|)|}" ))
2445+ return false ;
2446+ if (Token::simpleMatch (tok, " [ ]" ))
2447+ return false ;
2448+ if (Token::Match (tok->previous (), " %name% (" ) && tok->previous ()->isKeyword ())
2449+ return false ;
2450+ if (Token::Match (tok, " <|>" ) && tok->link ())
2451+ return false ;
2452+ if (Token::simpleMatch (tok, " [" ) && tok->astOperand1 ())
2453+ return isMutableExpression (tok->astOperand1 ());
2454+ if (const Variable* var = tok->variable ()) {
2455+ if (var->nameToken () == tok)
2456+ return false ;
2457+ if (!var->isPointer () && var->isConst ())
2458+ return false ;
2459+ }
2460+ return true ;
2461+ }
2462+
24382463bool isVariableChangedByFunctionCall (const Token *tok, int indirect, const Settings &settings, bool *inconclusive)
24392464{
24402465 if (!tok)
@@ -2545,7 +2570,7 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
25452570
25462571bool isVariableChanged (const Token *tok, int indirect, const Settings &settings, int depth)
25472572{
2548- if (!tok)
2573+ if (!isMutableExpression ( tok) )
25492574 return false ;
25502575
25512576 if (indirect == 0 && isConstVarExpression (tok))
@@ -2594,12 +2619,12 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings,
25942619 tok2 = skipRedundantPtrOp (tok2, tok2->astParent ());
25952620
25962621 if (tok2->astParent () && tok2->astParent ()->isAssignmentOp ()) {
2597- if (((indirect == 0 || tok2 != tok) || (indirect == 1 && tok2-> str () == " . " )) && tok2 == tok2-> astParent ()-> astOperand1 ( ))
2622+ if (astIsLHS ( tok2))
25982623 return true ;
25992624 // Check if assigning to a non-const lvalue
26002625 const Variable * var = getLHSVariable (tok2->astParent ());
2601- if (var && var->isReference () && !var->isConst () &&
2602- (( var->nameToken () && var-> nameToken ()-> next () == tok2->astParent ()) || var-> isPointer () )) {
2626+ if (var && var->isReference () && !var->isConst () && var-> nameToken () &&
2627+ var->nameToken ()-> next () == tok2->astParent ()) {
26032628 if (!var->isLocal () || isVariableChanged (var, settings, depth - 1 ))
26042629 return true ;
26052630 }
@@ -2815,7 +2840,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
28152840{
28162841 if (depth < 0 )
28172842 return true ;
2818- if (tok-> isLiteral () || tok-> isKeyword () || tok-> isStandardType () || Token::Match (tok, " ,|;|: " ))
2843+ if (! isMutableExpression ( tok))
28192844 return false ;
28202845 if (tok->exprId () != exprid || (!tok->varId () && !tok->isName ())) {
28212846 if (globalvar && Token::Match (tok, " %name% (" ) && !(tok->function () && tok->function ()->isAttributePure ()))
0 commit comments