@@ -4966,6 +4966,24 @@ static void valueFlowCondition(const ValuePtr<ConditionHandler>& handler,
49664966 handler->afterCondition (tokenlist, symboldatabase, errorLogger, settings, skippedFunctions);
49674967}
49684968
4969+ static const Token* getConditionVariable (const Token* tok)
4970+ {
4971+ if (tok->str () == " !" )
4972+ return tok->astOperand1 ();
4973+
4974+ if (const Token* parent = tok->astParent ()) {
4975+ if (Token::Match (parent, " %oror%|&&|?" ) ||
4976+ Token::Match (parent->previous (), " if|while (" ) ||
4977+ (parent->str () == " ;" && Token::simpleMatch (parent->astParent (), " ;" ))) {
4978+ if (Token::simpleMatch (tok, " =" ))
4979+ return tok->astOperand1 ();
4980+ if (!Token::Match (tok, " %comp%|%assign%" ))
4981+ return tok;
4982+ }
4983+ }
4984+ return nullptr ;
4985+ }
4986+
49694987struct SimpleConditionHandler : ConditionHandler {
49704988 std::vector<Condition> parse (const Token* tok, const Settings& /* settings*/ ) const override {
49714989
@@ -4984,19 +5002,7 @@ struct SimpleConditionHandler : ConditionHandler {
49845002 if (!conds.empty ())
49855003 return conds;
49865004
4987- const Token* vartok = nullptr ;
4988-
4989- if (tok->str () == " !" ) {
4990- vartok = tok->astOperand1 ();
4991-
4992- } else if (tok->astParent () && (Token::Match (tok->astParent (), " %oror%|&&|?" ) ||
4993- Token::Match (tok->astParent ()->previous (), " if|while (" ))) {
4994- if (Token::simpleMatch (tok, " =" ))
4995- vartok = tok->astOperand1 ();
4996- else if (!Token::Match (tok, " %comp%|%assign%" ))
4997- vartok = tok;
4998- }
4999-
5005+ const Token* vartok = getConditionVariable (tok);
50005006 if (!vartok)
50015007 return {};
50025008 Condition cond;
0 commit comments