Fix #10174 debug: Executable scope 'x' with unknown function (#3972)

* Fix #10174 debug: Executable scope 'x' with unknown function

* Format
This commit is contained in:
chrchr-github 2022-04-05 07:34:06 +02:00 committed by GitHub
parent aae810dd2c
commit b79885c6af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -2692,6 +2692,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
(Token::Match(second->next(), "%name% <") &&
Token::Match(second->linkAt(1), "> :: %name%"))) &&
((second->next()->str() == scope->className) ||
(scope->nestedIn && second->next()->str() == scope->nestedIn->className) ||
(scope->definedType && scope->definedType->isDerivedFrom(second->next()->str()))) &&
(first->next()->str() == second->strAt(3))) {
if (Token::Match(second->next(), "%name% <"))

View File

@ -357,6 +357,7 @@ private:
TEST_CASE(symboldatabase96); // #10126
TEST_CASE(symboldatabase97); // #10598 - final class
TEST_CASE(symboldatabase98); // #10451
TEST_CASE(symboldatabase100); // #10174
TEST_CASE(createSymbolDatabaseFindAllScopes1);
TEST_CASE(createSymbolDatabaseFindAllScopes2);
@ -4879,6 +4880,23 @@ private:
}
}
void symboldatabase100() { // #10174
GET_SYMBOL_DB("namespace N {\n"
" struct S {};\n"
" struct T { void f(S s); };\n"
" void T::f(N::S s) {}\n"
"}\n");
ASSERT(db);
ASSERT_EQUALS(1, db->functionScopes.size());
auto it = std::find_if(db->scopeList.begin(), db->scopeList.end(), [](const Scope& s) {
return s.className == "T";
});
ASSERT(it != db->scopeList.end());
const Function* function = findFunctionByName("f", &*it);
ASSERT(function && function->token->str() == "f");
ASSERT(function->hasBody());
}
void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);