@@ -1987,7 +1987,15 @@ void CheckOther::checkDuplicateExpression()
19871987 if (tok->isOp () && tok->astOperand1 () && !Token::Match (tok, " +|*|<<|>>|+=|*=|<<=|>>=" )) {
19881988 if (Token::Match (tok, " ==|!=|-" ) && astIsFloat (tok->astOperand1 (), true ))
19891989 continue ;
1990- if (isSameExpression (mTokenizer ->isCPP (), true , tok->astOperand1 (), tok->astOperand2 (), mSettings ->library , true , true , &errorPath)) {
1990+ const bool followVar = !isConstVarExpression (tok) || Token::Match (tok, " %comp%|%oror%|&&" );
1991+ if (isSameExpression (mTokenizer ->isCPP (),
1992+ true ,
1993+ tok->astOperand1 (),
1994+ tok->astOperand2 (),
1995+ mSettings ->library ,
1996+ true ,
1997+ followVar,
1998+ &errorPath)) {
19911999 if (isWithoutSideEffects (mTokenizer ->isCPP (), tok->astOperand1 ())) {
19922000 const bool assignment = tok->str () == " =" ;
19932001 if (assignment && warningEnabled)
@@ -2005,17 +2013,39 @@ void CheckOther::checkDuplicateExpression()
20052013 duplicateExpressionError (tok->astOperand1 (), tok->astOperand2 (), tok, errorPath);
20062014 }
20072015 }
2008- } else if (tok->str () == " =" && Token::simpleMatch (tok->astOperand2 (), " =" ) && isSameExpression (mTokenizer ->isCPP (), false , tok->astOperand1 (), tok->astOperand2 ()->astOperand1 (), mSettings ->library , true , false )) {
2016+ } else if (tok->str () == " =" && Token::simpleMatch (tok->astOperand2 (), " =" ) &&
2017+ isSameExpression (mTokenizer ->isCPP (),
2018+ false ,
2019+ tok->astOperand1 (),
2020+ tok->astOperand2 ()->astOperand1 (),
2021+ mSettings ->library ,
2022+ true ,
2023+ false )) {
20092024 if (warningEnabled && isWithoutSideEffects (mTokenizer ->isCPP (), tok->astOperand1 ())) {
20102025 selfAssignmentError (tok, tok->astOperand1 ()->expressionString ());
20112026 }
20122027 } else if (styleEnabled &&
2013- isOppositeExpression (mTokenizer ->isCPP (), tok->astOperand1 (), tok->astOperand2 (), mSettings ->library , false , true , &errorPath) &&
2028+ isOppositeExpression (mTokenizer ->isCPP (),
2029+ tok->astOperand1 (),
2030+ tok->astOperand2 (),
2031+ mSettings ->library ,
2032+ false ,
2033+ true ,
2034+ &errorPath) &&
20142035 !Token::Match (tok, " =|-|-=|/|/=" ) &&
20152036 isWithoutSideEffects (mTokenizer ->isCPP (), tok->astOperand1 ())) {
20162037 oppositeExpressionError (tok, errorPath);
20172038 } else if (!Token::Match (tok, " [-/%]" )) { // These operators are not associative
2018- if (styleEnabled && tok->astOperand2 () && tok->str () == tok->astOperand1 ()->str () && isSameExpression (mTokenizer ->isCPP (), true , tok->astOperand2 (), tok->astOperand1 ()->astOperand2 (), mSettings ->library , true , true , &errorPath) && isWithoutSideEffects (mTokenizer ->isCPP (), tok->astOperand2 ()))
2039+ if (styleEnabled && tok->astOperand2 () && tok->str () == tok->astOperand1 ()->str () &&
2040+ isSameExpression (mTokenizer ->isCPP (),
2041+ true ,
2042+ tok->astOperand2 (),
2043+ tok->astOperand1 ()->astOperand2 (),
2044+ mSettings ->library ,
2045+ true ,
2046+ followVar,
2047+ &errorPath) &&
2048+ isWithoutSideEffects (mTokenizer ->isCPP (), tok->astOperand2 ()))
20192049 duplicateExpressionError (tok->astOperand2 (), tok->astOperand1 ()->astOperand2 (), tok, errorPath);
20202050 else if (tok->astOperand2 () && isConstExpression (tok->astOperand1 (), mSettings ->library , true , mTokenizer ->isCPP ())) {
20212051 const Token *ast1 = tok->astOperand1 ();
0 commit comments