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

Fix #11602 "debug: Executable scope 'x' with unknown function" #4869

Merged
merged 5 commits into from
Mar 9, 2023
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
25 changes: 17 additions & 8 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,18 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
(Token::simpleMatch(first, "( void )") && Token::simpleMatch(second, "( )")))
return true;

auto skipTopLevelConst = [](const Token* start) -> const Token* {
const Token* tok = start->next();
if (Token::simpleMatch(tok, "const")) {
tok = tok->next();
while (Token::Match(tok, "%name%|%type%|::"))
tok = tok->next();
if (Token::Match(tok, ",|)|="))
return start->next();
}
return start;
};

while (first->str() == second->str() &&
first->isLong() == second->isLong() &&
first->isUnsigned() == second->isUnsigned()) {
Expand All @@ -2704,15 +2716,12 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
second = second->next();

// skip const on type passed by value
if (Token::Match(first->next(), "const %type% %name%|,|)") &&
!Token::Match(first->next(), "const %type% %name%| ["))
first = first->next();
if (Token::Match(second->next(), "const %type% %name%|,|)") &&
!Token::Match(second->next(), "const %type% %name%| ["))
second = second->next();
const Token* const oldSecond = second;
first = skipTopLevelConst(first);
second = skipTopLevelConst(second);

// skip default value assignment
else if (first->next()->str() == "=") {
if (oldSecond == second && first->next()->str() == "=") {
first = first->nextArgument();
if (first)
first = first->tokAt(-2);
Expand All @@ -2726,7 +2735,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
} else if (!first) { // End of argument list (first)
return !second->nextArgument(); // End of argument list (second)
}
} else if (second->next()->str() == "=") {
} else if (oldSecond == second && second->next()->str() == "=") {
second = second->nextArgument();
if (second)
second = second->tokAt(-2);
Expand Down
58 changes: 41 additions & 17 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5138,23 +5138,47 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void symboldatabase104() { // #11535
GET_SYMBOL_DB("struct S {\n"
" void f1(char* const c);\n"
" void f2(char* const c);\n"
" void f3(char* const);\n"
" void f4(char* c);\n"
" void f5(char* c);\n"
" void f6(char*);\n"
"};\n"
"void S::f1(char* c) {}\n"
"void S::f2(char*) {}\n"
"void S::f3(char* c) {}\n"
"void S::f4(char* const c) {}\n"
"void S::f5(char* const) {}\n"
"void S::f6(char* const c) {}\n");
ASSERT(db != nullptr);
ASSERT_EQUALS("", errout.str());
void symboldatabase104() {
const bool oldDebug = settings1.debugwarnings;
settings1.debugwarnings = true;
{
GET_SYMBOL_DB("struct S {\n" // #11535
" void f1(char* const c);\n"
" void f2(char* const c);\n"
" void f3(char* const);\n"
" void f4(char* c);\n"
" void f5(char* c);\n"
" void f6(char*);\n"
"};\n"
"void S::f1(char* c) {}\n"
"void S::f2(char*) {}\n"
"void S::f3(char* c) {}\n"
"void S::f4(char* const c) {}\n"
"void S::f5(char* const) {}\n"
"void S::f6(char* const c) {}\n");
ASSERT(db != nullptr);
ASSERT_EQUALS("", errout.str());
}
{
GET_SYMBOL_DB("struct S2 {\n" // #11602
" enum E {};\n"
"};\n"
"struct S1 {\n"
" void f(S2::E) const;\n"
"};\n"
"void S1::f(const S2::E) const {}\n");
ASSERT(db != nullptr);
ASSERT_EQUALS("", errout.str());
}
{
GET_SYMBOL_DB("struct S {\n"
" void f(const bool b = false);\n"
"};\n"
"void S::f(const bool b) {}\n");
ASSERT(db != nullptr);
ASSERT_EQUALS("", errout.str());
}
settings1.debugwarnings = oldDebug;
}

void createSymbolDatabaseFindAllScopes1() {
Expand Down