CheckCondition: Break out code to check if function call is non-const
This commit is contained in:
parent
e0c7f7f8f2
commit
4c30a5af25
|
@ -454,6 +454,20 @@ void CheckCondition::multiConditionError(const Token *tok, unsigned int line1)
|
||||||
// - same condition after early exit => always false
|
// - same condition after early exit => always false
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static bool isNonConstFunctionCall(const Token *ftok)
|
||||||
|
{
|
||||||
|
const Token *obj = ftok->next()->astOperand1();
|
||||||
|
while (obj && obj->str() == ".")
|
||||||
|
obj = obj->astOperand1();
|
||||||
|
if (!obj)
|
||||||
|
return true;
|
||||||
|
else if (obj->variable() && obj->variable()->isConst())
|
||||||
|
return false;
|
||||||
|
else if (ftok->function() && ftok->function()->isConst())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckCondition::multiCondition2()
|
void CheckCondition::multiCondition2()
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled(Settings::WARNING))
|
if (!_settings->isEnabled(Settings::WARNING))
|
||||||
|
@ -493,17 +507,7 @@ void CheckCondition::multiCondition2()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(cond, "%name% (")) {
|
if (Token::Match(cond, "%name% (")) {
|
||||||
const Token *obj = cond->next()->astOperand1();
|
nonConstFunctionCall = isNonConstFunctionCall(cond);
|
||||||
while (obj && obj->str() == ".")
|
|
||||||
obj = obj->astOperand1();
|
|
||||||
if (!obj)
|
|
||||||
nonConstFunctionCall = true;
|
|
||||||
else if (obj->variable() && obj->variable()->isConst())
|
|
||||||
;
|
|
||||||
else if (cond->function() && cond->function()->isConst())
|
|
||||||
;
|
|
||||||
else
|
|
||||||
nonConstFunctionCall = true;
|
|
||||||
if (nonConstFunctionCall)
|
if (nonConstFunctionCall)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -581,7 +585,7 @@ void CheckCondition::multiCondition2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "%type% (") && nonlocal) // function call -> bailout if there are nonlocal variables
|
if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok)) // non const function call -> bailout if there are nonlocal variables
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok, "break|continue|return|throw") && tok->scope() == endToken->scope())
|
if (Token::Match(tok, "break|continue|return|throw") && tok->scope() == endToken->scope())
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue