Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,15 @@ const Token* findLambdaEndTokenWithoutAST(const Token* tok) {
tok = tok->link()->next();
if (Token::simpleMatch(tok, "(") && tok->link())
tok = tok->link()->next();
if (Token::simpleMatch(tok, ".")) { // trailing return type
tok = tok->next();
while (Token::Match(tok, "%type%|%name%|::|&|&&|*|<|(")) {
if (tok->link())
tok = tok->link()->next();
else
tok = tok->next();
}
}
if (!(Token::simpleMatch(tok, "{") && tok->link()))
return nullptr;
return tok->link()->next();
Expand Down
45 changes: 36 additions & 9 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2814,15 +2814,42 @@ class TestSymbolDatabase : public TestFixture {
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 functionArgs20() {
{
const char code[] = "void f(void *(*g)(void *) = [](void *p) { return p; }) {}"; // #11769
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());
}
{
const char code[] = "void f() { auto g = [&](const std::function<int(int)>& h = [](int i) -> int { return i; }) {}; }"; // #12338
GET_SYMBOL_DB(code);
ASSERT(db != nullptr);
ASSERT_EQUALS(3, db->scopeList.size());
ASSERT_EQUALS(Scope::ScopeType::eLambda, db->scopeList.back().type);
}
{
const char code[] = "void f() {\n"
" auto g = [&](const std::function<const std::vector<int>&(const std::vector<int>&)>& h = [](const std::vector<int>& v) -> const std::vector<int>& { return v; }) {};\n"
"}\n";
GET_SYMBOL_DB(code);
ASSERT(db != nullptr);
ASSERT_EQUALS(3, db->scopeList.size());
ASSERT_EQUALS(Scope::ScopeType::eLambda, db->scopeList.back().type);
}
{
const char code[] = "void f() {\n"
" auto g = [&](const std::function<int(int)>& h = [](int i) -> decltype(0) { return i; }) {};\n"
"}\n";
GET_SYMBOL_DB(code);
ASSERT(db != nullptr);
ASSERT_EQUALS(3, db->scopeList.size());
ASSERT_EQUALS(Scope::ScopeType::eLambda, db->scopeList.back().type);
}
}

void functionArgs21() {
Expand Down