Fixed #6876 (valueFlowForward: lambda function)

This commit is contained in:
Daniel Marjamäki 2015-07-26 19:28:42 +02:00
parent 7c48bf3ca5
commit ed1c6e41d9
2 changed files with 23 additions and 0 deletions

View File

@ -1367,6 +1367,18 @@ static bool valueFlowForward(Token * const startToken,
it->inconclusive = true; it->inconclusive = true;
} }
} }
// Lambda function
if (Token::simpleMatch(tok2, "= [") &&
Token::simpleMatch(tok2->linkAt(1), "] (") &&
Token::simpleMatch(tok2->linkAt(1)->linkAt(1), ") {")) {
const Token *bodyStart = tok2->linkAt(1)->linkAt(1)->next();
if (isVariableChanged(bodyStart, bodyStart->link(), varid)) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "valueFlowForward, " + var->name() + " is changed in lambda function");
return false;
}
}
} }
return true; return true;
} }

View File

@ -726,6 +726,17 @@ private:
"}"; "}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
// lambda
code = "void f() {\n"
" int x = 0;\n"
" Q q = [&]() {\n"
" if (x > 0) {}\n"
" x++;\n"
" };\n"
" dosomething(q);\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
// if/else // if/else
code = "void f() {\n" code = "void f() {\n"
" int x = 123;\n" " int x = 123;\n"