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

This commit is contained in:
Daniel Marjamäki 2019-01-26 21:43:44 +01:00
parent b1797ee15b
commit 2bba9ac78a
2 changed files with 12 additions and 2 deletions

View File

@ -1102,7 +1102,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
continue; continue;
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (Token::simpleMatch(tok, "] (")) if (findLambdaEndToken(tok))
// todo: handle lambdas // todo: handle lambdas
break; break;
if (Token::simpleMatch(tok, "try {")) if (Token::simpleMatch(tok, "try {"))

View File

@ -181,7 +181,7 @@ private:
TEST_CASE(localvarFuncPtr); // #7194 TEST_CASE(localvarFuncPtr); // #7194
TEST_CASE(localvarAddr); // #7477 TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarDelete); TEST_CASE(localvarDelete);
TEST_CASE(localvarLambda); // #8941 TEST_CASE(localvarLambda); // #8941, #8948
TEST_CASE(localvarCppInitialization); TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization); TEST_CASE(localvarCpp11Initialization);
@ -4246,6 +4246,16 @@ private:
" return f() + g();\n" " return f() + g();\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
functionVariableUsage("void foo(std::vector<int>& v) {\n"
" int n = 0;\n"
" std::generate(v.begin(), v.end(), [&n] {\n"
" int r = n;\n"
" n += 2;\n"
" return r;\n"
" });\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void localvarCppInitialization() { void localvarCppInitialization() {