Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12420: SymbolDatabase: function in blockscope #5960

Merged
merged 7 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 30 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,32 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} else {
tok = tok->link();
}
} else if (Token::Match(tok, "%name% (")) {
if (tok->next() && Token::Match(tok->next()->link(), ") ;")) {
const Token *funcStart = nullptr;
danmar marked this conversation as resolved.
Show resolved Hide resolved
const Token *argStart = nullptr;
const Token *declEnd = nullptr;
if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) {
if (declEnd && declEnd->str() == ";") {
bool newFunc = true; // Is this function already in the database?
auto range = scope->functionMap.equal_range(tok->str());
for (std::multimap<std::string, const Function*>::const_iterator it = range.first; it != range.second; ++it) {
if (it->second->argsMatch(scope, it->second->argDef, argStart, emptyString, 0)) {
newFunc = false;
break;
}
}
// save function prototype in database
if (newFunc) {
Function function(tok, scope, funcStart, argStart);
if (function.isExtern())
scope->addFunction(std::move(function));
}
tok = declEnd;
continue;
}
}
}
}
// syntax error?
if (!scope)
Expand Down Expand Up @@ -5892,6 +5918,10 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const
// find the scope this function is in
const Scope *currScope = tok->scope();
while (currScope && currScope->isExecutable()) {
if (const Function* f = currScope->findFunction(tok)) {
if (f->isExtern())
return f;
}
if (currScope->functionOf)
currScope = currScope->functionOf;
else
Expand Down
2 changes: 1 addition & 1 deletion test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6957,7 +6957,7 @@ class TestUnusedVar : public TestFixture {
" int x = 0;\n"
" std::for_each(ints.begin(), ints.end(), [&x](int i){ x += i; });\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
danmar marked this conversation as resolved.
Show resolved Hide resolved
}

void namespaces() { // #7557
Expand Down
Loading