parent
edde0eedaa
commit
64fbffc90d
|
@ -599,9 +599,9 @@ bool isConstExpression(const Token *tok, const Library& library, bool pure, bool
|
|||
}
|
||||
if (tok->tokType() == Token::eIncDecOp)
|
||||
return false;
|
||||
if(tok->isAssignmentOp())
|
||||
if (tok->isAssignmentOp())
|
||||
return false;
|
||||
if(isLikelyStreamRead(cpp, tok))
|
||||
if (isLikelyStreamRead(cpp, tok))
|
||||
return false;
|
||||
// bailout when we see ({..})
|
||||
if (tok->str() == "{")
|
||||
|
|
|
@ -1237,20 +1237,20 @@ void CheckCondition::clarifyConditionError(const Token *tok, bool assign, bool b
|
|||
|
||||
static bool isConstVarExpression(const Token * tok)
|
||||
{
|
||||
if(!tok)
|
||||
if (!tok)
|
||||
return false;
|
||||
if(Token::Match(tok, "%cop%")) {
|
||||
if(tok->astOperand1() && !isConstVarExpression(tok->astOperand1()))
|
||||
if (Token::Match(tok, "%cop%")) {
|
||||
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1()))
|
||||
return false;
|
||||
if(tok->astOperand2() && !isConstVarExpression(tok->astOperand2()))
|
||||
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if(Token::Match(tok, "%bool%|%num%|%str%|%char%|nullptr|NULL"))
|
||||
if (Token::Match(tok, "%bool%|%num%|%str%|%char%|nullptr|NULL"))
|
||||
return true;
|
||||
if(tok->isEnumerator())
|
||||
if (tok->isEnumerator())
|
||||
return true;
|
||||
if(tok->variable())
|
||||
if (tok->variable())
|
||||
return tok->variable()->isConst();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2068,8 +2068,8 @@ void CheckOther::checkDuplicateExpression()
|
|||
else if (tok->astOperand2() && isConstExpression(tok->astOperand1(), mSettings->library, true, mTokenizer->isCPP())) {
|
||||
const Token *ast1 = tok->astOperand1();
|
||||
while (ast1 && tok->str() == ast1->str()) {
|
||||
if (isSameExpression(mTokenizer->isCPP(), true, ast1->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath) &&
|
||||
isWithoutSideEffects(mTokenizer->isCPP(), ast1->astOperand1()) &&
|
||||
if (isSameExpression(mTokenizer->isCPP(), true, ast1->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath) &&
|
||||
isWithoutSideEffects(mTokenizer->isCPP(), ast1->astOperand1()) &&
|
||||
isWithoutSideEffects(mTokenizer->isCPP(), ast1->astOperand2()))
|
||||
// Probably the message should be changed to 'duplicate expressions X in condition or something like that'.
|
||||
duplicateExpressionError(ast1->astOperand1(), tok->astOperand2(), tok, errorPath);
|
||||
|
|
Loading…
Reference in New Issue