Fix #11769 cppcheckError for function with lambda as default parameter (#5159)

This commit is contained in:
chrchr-github 2023-06-17 17:03:19 +02:00 committed by GitHub
parent fd3befe60a
commit 53cab34484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -4311,7 +4311,13 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
initArgCount++;
if (tok->strAt(1) == "[") {
const Token* lambdaStart = tok->next();
tok = type == eLambda ? findLambdaEndTokenWithoutAST(lambdaStart) : findLambdaEndToken(lambdaStart);
if (type == eLambda)
tok = findLambdaEndTokenWithoutAST(lambdaStart);
else {
tok = findLambdaEndToken(lambdaStart);
if (!tok)
tok = findLambdaEndTokenWithoutAST(lambdaStart);
}
if (!tok)
throw InternalError(lambdaStart, "Analysis failed (lambda not recognized). If the code is valid then please report this failure.", InternalError::INTERNAL);
}

View File

@ -246,6 +246,7 @@ private:
TEST_CASE(functionArgs17);
TEST_CASE(functionArgs18); // #10376
TEST_CASE(functionArgs19); // #10376
TEST_CASE(functionArgs20);
TEST_CASE(functionImplicitlyVirtual);
@ -2707,6 +2708,17 @@ private:
ASSERT_EQUALS(3, func->argCount());
}
void functionArgs20() { // #11769
const char code[] = "void f(void *(*g)(void *) = [](void *p) { return p; }) {}";
GET_SYMBOL_DB(code);
ASSERT(db != nullptr);
const Scope *scope = db->functionScopes.front();
const Function *func = scope->function;
ASSERT_EQUALS(1, func->argCount());
const Variable* arg = func->getArgumentVar(0);
TODO_ASSERT(arg->hasDefault());
}
void functionImplicitlyVirtual() {
GET_SYMBOL_DB("class base { virtual void f(); };\n"
"class derived : base { void f(); };\n"