valueFlowBefore: better analysis of conditional assignment
This commit is contained in:
parent
cdf081dbd5
commit
df799f97c5
|
@ -509,7 +509,10 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
}
|
||||
|
||||
if (tok2->str() == "}") {
|
||||
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
|
||||
const Token *vartok = Token::findmatch(tok2->link(), "%varid%", tok2, varid);
|
||||
while (Token::Match(vartok, "%var% = %num% ;") && !vartok->tokAt(2)->getValue(num))
|
||||
vartok = Token::findmatch(vartok->next(), "%varid%", tok2, varid);
|
||||
if (vartok) {
|
||||
if (settings->debugwarnings) {
|
||||
std::string errmsg = "variable ";
|
||||
if (var)
|
||||
|
|
|
@ -430,6 +430,13 @@ private:
|
|||
" if (x == 123) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on }\n", errout.str());
|
||||
|
||||
code = "void f(int x) {\n"
|
||||
" a = x;\n"
|
||||
" if (abc) { x = 1; }\n" // <- condition must be false if x is 7 in next line
|
||||
" if (x == 7) { }\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 7));
|
||||
}
|
||||
|
||||
void valueFlowBeforeConditionGlobalVariables() {
|
||||
|
|
Loading…
Reference in New Issue