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