ValueFlow: Skip wrong handling of lambda functions. TODO: handle lambda functions properly.

This commit is contained in:
Daniel Marjamäki 2017-08-28 22:39:12 +02:00
parent 017e72d145
commit 9c99bc43c2
2 changed files with 30 additions and 0 deletions

View File

@ -1348,6 +1348,15 @@ static bool valueFlowForward(Token * const startToken,
}
}
// jump over lambda function
if (Token::simpleMatch(tok2, "= [") && Token::simpleMatch(tok2->linkAt(1), "] (") && Token::simpleMatch(tok2->linkAt(1)->linkAt(1), ") {")) {
// TODO: handle lambda functions
tok2 = tok2->linkAt(1); // Goto ]
tok2 = tok2->linkAt(1); // Goto )
tok2 = tok2->linkAt(1); // Goto }
continue;
}
if (Token::Match(tok2, "[;{}] %name% :") || tok2->str() == "case") {
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it)
it->changeKnownToPossible();

View File

@ -78,6 +78,7 @@ private:
TEST_CASE(valueFlowAfterCondition);
TEST_CASE(valueFlowForwardCompoundAssign);
TEST_CASE(valueFlowForwardCorrelatedVariables);
TEST_CASE(valueFlowForwardLambda);
TEST_CASE(valueFlowSwitchVariable);
@ -1784,6 +1785,26 @@ private:
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
}
void valueFlowForwardLambda() {
const char *code;
code = "void f() {\n"
" int x=1;\n"
" auto f = [&](){ a=x; }\n" // x is not 1
" x = 2;\n"
" f();\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 1));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 3U, 2));
code = "void f() {\n"
" int x=3;\n"
" auto f = [&](){ a=x; }\n" // todo: x is 3
" f();\n"
"}";
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 3U, 3));
}
void valueFlowBitAnd() {
const char *code;