Fixed #8949 (False Positive: Variable 'f' is assigned a value that is never used.)

This commit is contained in:
Daniel Marjamäki 2019-01-22 21:16:27 +01:00
parent d35a26c6f0
commit 8c07be136a
2 changed files with 16 additions and 2 deletions

View File

@ -1108,6 +1108,13 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
// TODO
return Result(Result::Type::BAILOUT);
if (const Token *lambdaEndToken = findLambdaEndToken(tok)) {
tok = lambdaEndToken;
const Result lambdaResult = checkRecursive(expr, lambdaEndToken->link()->next(), lambdaEndToken, exprVarIds, local);
if (lambdaResult.type == Result::Type::READ || lambdaResult.type == Result::Type::BAILOUT)
return lambdaResult;
}
if (Token::Match(tok, "return|throw")) {
// TODO: Handle these better
// Is expr variable used in expression?

View File

@ -181,7 +181,7 @@ private:
TEST_CASE(localvarFuncPtr); // #7194
TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarDelete);
TEST_CASE(localvarReturnCallLambda); // #8941
TEST_CASE(localvarLambda); // #8941
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
@ -4233,12 +4233,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarReturnCallLambda() {
void localvarLambda() {
functionVariableUsage("int foo() {\n"
" auto f = []{return 1};\n"
" return f();\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("int foo() {\n"
" auto f = []{return 1};\n"
" auto g = []{return 1};\n"
" return f() + g();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarCppInitialization() {