From 53cab34484a70942f59a475e4d022f24de1e3af5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 17 Jun 2023 17:03:19 +0200 Subject: [PATCH] Fix #11769 cppcheckError for function with lambda as default parameter (#5159) --- lib/symboldatabase.cpp | 8 +++++++- test/testsymboldatabase.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c1817f301..da189b629 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 159c4a7e9..a9d0af457 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"