Fixed #7363 (valueflowOppositeCondition - if (size1 > size2) ... else if (size1 < size2) ...)

This commit is contained in:
Daniel Marjamäki 2016-01-30 22:13:03 +01:00
parent 3b046b42a6
commit d5884692df
2 changed files with 7 additions and 1 deletions

View File

@ -733,7 +733,7 @@ static void valueFlowOppositeCondition(SymbolDatabase *symboldatabase, const Set
const Token *cond2 = tok2->tokAt(4)->astOperand2();
if (!cond2 || !cond2->isComparisonOp())
continue;
if (isOppositeCond(false, cpp, cond1, cond2, settings->library.functionpure)) {
if (isOppositeCond(true, cpp, cond1, cond2, settings->library.functionpure)) {
ValueFlow::Value value(1);
value.setKnown();
setTokenValue(const_cast<Token*>(cond2), value);

View File

@ -1897,6 +1897,12 @@ private:
ASSERT_EQUALS(1, value.intvalue);
ASSERT(value.isKnown());
code = "int f(int x) {\n"
" if (x < 2) {}\n"
" else if (x > 2) {}\n" // <- possible value
"}";
ASSERT(isNotKnownValues(code, ">"));
// function
code = "int f(int x) { return x + 1; }\n" // <- possible value
"void a() { f(12); }\b";