Fixed #7756 (ValueFlow: fix bug in valueAfterAssign, same variable in lhs and rhs)
This commit is contained in:
parent
d09a8dde57
commit
ad74421526
|
@ -1674,7 +1674,18 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat
|
|||
}
|
||||
}
|
||||
|
||||
valueFlowForward(tok, endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings);
|
||||
// Skip RHS
|
||||
const Token *nextExpression = tok->astOperand2();
|
||||
for (;;) {
|
||||
if (nextExpression->astOperand2())
|
||||
nextExpression = nextExpression->astOperand2();
|
||||
else if (nextExpression->isUnaryPreOp())
|
||||
nextExpression = nextExpression->astOperand1();
|
||||
else break;
|
||||
}
|
||||
nextExpression = nextExpression->next();
|
||||
|
||||
valueFlowForward(const_cast<Token *>(nextExpression), endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -772,6 +772,13 @@ private:
|
|||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 9));
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 8));
|
||||
|
||||
code = "void x() {\n"
|
||||
" int x = value ? 6 : 0;\n"
|
||||
" x =\n"
|
||||
" 1 + x;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 7));
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" y = x += z;\n"
|
||||
|
|
Loading…
Reference in New Issue