Skip to content

Commit 366a832

Browse files
committed
Merge pull request danmar#680 from Dmitry-Me/eliminateSetObject
Get rid of set object
2 parents 7ae7cdd + 70d98c7 commit 366a832

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/valueflow.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
365365
// is condition only depending on 1 variable?
366366
std::stack<const Token*> tokens;
367367
tokens.push(parent->astOperand1());
368-
std::set<unsigned int> variables; // used variables
368+
unsigned int varId = 0;
369369
while (!tokens.empty()) {
370370
const Token *t = tokens.top();
371371
tokens.pop();
@@ -374,9 +374,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
374374
tokens.push(t->astOperand1());
375375
tokens.push(t->astOperand2());
376376
if (t->varId()) {
377-
variables.insert(t->varId());
378-
if (variables.size() > 1U || value.varId != 0U)
377+
if (varId > 0 || value.varId != 0U)
379378
return;
379+
varId = t->varId();
380380
} else if (t->str() == "(" && Token::Match(t->previous(), "%name%"))
381381
return; // function call
382382
}
@@ -385,8 +385,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
385385
v.conditional = true;
386386
v.changeKnownToPossible();
387387

388-
if (!variables.empty())
389-
v.varId = *(variables.begin());
388+
if (varId)
389+
v.varId = varId;
390390

391391
setTokenValue(parent, v);
392392
}

0 commit comments

Comments
 (0)