Fixed #7159 (wrong handling of function parameters)

This commit is contained in:
Dmitry-Me 2019-12-31 18:26:12 +03:00
parent f55d72e821
commit 895910b769
2 changed files with 30 additions and 1 deletions

View File

@ -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());
}
}
}
}

View File

@ -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"