Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 9, 2024
1 parent c62b2d0 commit 3e67393
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
57 changes: 30 additions & 27 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,31 +720,6 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
else if (scope->type == Scope::eCatch)
scope->checkVariable(tok->tokAt(2), AccessControl::Throw, mSettings); // check for variable declaration and add it to new scope if found
tok = scopeStartTok;
} else if (Token::Match(tok, "%name% (")) {
const Token *funcStart = nullptr;
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;
}
}

} else if (Token::Match(tok, "%var% {")) {
endInitList.emplace(tok->next()->link(), scope);
tok = tok->next();
Expand All @@ -762,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;
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 @@ -5917,8 +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))
return f;
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());
}

void namespaces() { // #7557
Expand Down

0 comments on commit 3e67393

Please sign in to comment.