value flow: skip scopes that don't contain variable
This commit is contained in:
parent
81513b4346
commit
acb103e214
|
@ -103,7 +103,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (tok2->varId() == varid) {
|
||||
// bailout: assignment
|
||||
if (Token::Match(tok2->previous(), "!!* %var% =")) {
|
||||
|
@ -130,9 +130,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
}
|
||||
|
||||
if (tok2->str() == "}") {
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on }");
|
||||
break;
|
||||
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on }");
|
||||
break;
|
||||
} else {
|
||||
tok2 = tok2->link();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,12 +117,19 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: no simplification of x within ?: expression\n", errout.str());
|
||||
|
||||
code = "void f(int x) {\n"
|
||||
" int a = x;\n"
|
||||
" int a =v x;\n"
|
||||
" a = b ? x/2 : 20/x;\n"
|
||||
" if (x == 123) {}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
|
||||
|
||||
code = "void f(int x, int y) {\n"
|
||||
" a = x;\n"
|
||||
" if (y){}\n"
|
||||
" if (x==123){}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
|
||||
|
||||
// bailout: if/else/etc
|
||||
bailout("void f(int x) {\n"
|
||||
" if (x != 123) { b = x; }\n"
|
||||
|
|
Loading…
Reference in New Issue