Fix #9815 FP redundantInitialization with lambda / #10864 debug: valueFlowConditionExpressions bailout (#3970)

* Fix #9815 FP redundantInitialization with lambda

* Fix #10864 debug: valueFlowConditionExpressions bailout

* Format
This commit is contained in:
chrchr-github 2022-04-05 23:19:17 +02:00 committed by GitHub
parent f5313dc519
commit 4c375e7224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -3177,6 +3177,12 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
return Result(Result::Type::READ);
continue;
}
const auto startEnd = parent->astParent()->astOperand2()->findExpressionStartEndTokens();
for (const Token* tok2 = startEnd.first; tok2 != startEnd.second; tok2 = tok2->next()) {
if (tok2->tokType() == Token::eLambda)
return Result(Result::Type::BAILOUT);
// TODO: analyze usage in lambda
}
// ({ .. })
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
return Result(Result::Type::BAILOUT);

View File

@ -1432,7 +1432,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
if (Token::simpleMatch(tok->next(), ")") && Token::simpleMatch(tok->next()->link()->previous(), "catch ("))
continue;
// Very likely a typelist
if (Token::Match(tok->tokAt(-2), "%type% ,"))
if (Token::Match(tok->tokAt(-2), "%type% ,") || Token::Match(tok->next(), ", %type%"))
continue;
// Inside template brackets
if (Token::Match(tok->next(), "<|>") && tok->next()->link())

View File

@ -8104,6 +8104,13 @@ private:
" i = nullptr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int f(const std::vector<int>& v) {\n" // #9815
" int i = g();\n"
" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void redundantMemWrite() {

View File

@ -357,6 +357,7 @@ private:
TEST_CASE(symboldatabase96); // #10126
TEST_CASE(symboldatabase97); // #10598 - final class
TEST_CASE(symboldatabase98); // #10451
TEST_CASE(symboldatabase99); // #10864
TEST_CASE(symboldatabase100); // #10174
TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4880,6 +4881,11 @@ private:
}
}
void symboldatabase99() { // #10864
check("void f() { std::map<std::string, int> m; }");
ASSERT_EQUALS("", errout.str());
}
void symboldatabase100() {
{
GET_SYMBOL_DB("namespace N {\n" // #10174