From 895910b769db6646e2b3c8c6b93b8fe944cb1da7 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 31 Dec 2019 18:26:12 +0300 Subject: [PATCH] Fixed #7159 (wrong handling of function parameters) --- lib/symboldatabase.cpp | 6 +++++- test/testsymboldatabase.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c9cd3ecc6..ed06da17c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3428,8 +3428,12 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s // count default arguments for (const Token* tok = argDef->next(); tok && tok != argDef->link(); tok = tok->next()) { - if (tok->str() == "=") + if (tok->str() == "=") { initArgCount++; + if (tok->strAt(1) == "[") { + tok = findLambdaEndToken(tok->next()); + } + } } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e47bb7bd1..fc40abf16 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -218,6 +218,7 @@ private: TEST_CASE(functionArgs12); // #7661 TEST_CASE(functionArgs13); // #7697 TEST_CASE(functionArgs14); // #9055 + TEST_CASE(functionArgs15); // #7159 TEST_CASE(functionImplicitlyVirtual); @@ -2284,6 +2285,30 @@ private: ASSERT_EQUALS(2, func ? func->minArgCount() : 0); } + void functionArgs15() { // #7159 + const char code[] = + "class Class {\n" + " void Method(\n" + " char c = []()->char {\n" + " int d = rand();\n"// the '=' on this line used to reproduce the defect + " return d;\n" + " }()\n" + " );\n" + "};\n"; + GET_SYMBOL_DB(code); + ASSERT(db); + ASSERT_EQUALS(2, db->scopeList.size()); + const Scope& classScope = db->scopeList.back(); + ASSERT_EQUALS(Scope::eClass, classScope.type); + ASSERT_EQUALS("Class", classScope.className); + ASSERT_EQUALS(1, classScope.functionList.size()); + const Function& method = classScope.functionList.front(); + ASSERT_EQUALS("Method", method.name()); + ASSERT_EQUALS(1, method.argCount()); + ASSERT_EQUALS(1, method.initializedArgCount()); + ASSERT_EQUALS(0, method.minArgCount()); + } + void functionImplicitlyVirtual() { GET_SYMBOL_DB("class base { virtual void f(); };\n" "class derived : base { void f(); };\n"