Skip to content

Commit 49c5a5a

Browse files
Fix #11602 "debug: Executable scope 'x' with unknown function" (#4869)
1 parent 3013183 commit 49c5a5a

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed

lib/symboldatabase.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,18 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
26832683
(Token::simpleMatch(first, "( void )") && Token::simpleMatch(second, "( )")))
26842684
return true;
26852685

2686+
auto skipTopLevelConst = [](const Token* start) -> const Token* {
2687+
const Token* tok = start->next();
2688+
if (Token::simpleMatch(tok, "const")) {
2689+
tok = tok->next();
2690+
while (Token::Match(tok, "%name%|%type%|::"))
2691+
tok = tok->next();
2692+
if (Token::Match(tok, ",|)|="))
2693+
return start->next();
2694+
}
2695+
return start;
2696+
};
2697+
26862698
while (first->str() == second->str() &&
26872699
first->isLong() == second->isLong() &&
26882700
first->isUnsigned() == second->isUnsigned()) {
@@ -2704,15 +2716,12 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
27042716
second = second->next();
27052717

27062718
// skip const on type passed by value
2707-
if (Token::Match(first->next(), "const %type% %name%|,|)") &&
2708-
!Token::Match(first->next(), "const %type% %name%| ["))
2709-
first = first->next();
2710-
if (Token::Match(second->next(), "const %type% %name%|,|)") &&
2711-
!Token::Match(second->next(), "const %type% %name%| ["))
2712-
second = second->next();
2719+
const Token* const oldSecond = second;
2720+
first = skipTopLevelConst(first);
2721+
second = skipTopLevelConst(second);
27132722

27142723
// skip default value assignment
2715-
else if (first->next()->str() == "=") {
2724+
if (oldSecond == second && first->next()->str() == "=") {
27162725
first = first->nextArgument();
27172726
if (first)
27182727
first = first->tokAt(-2);
@@ -2726,7 +2735,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
27262735
} else if (!first) { // End of argument list (first)
27272736
return !second->nextArgument(); // End of argument list (second)
27282737
}
2729-
} else if (second->next()->str() == "=") {
2738+
} else if (oldSecond == second && second->next()->str() == "=") {
27302739
second = second->nextArgument();
27312740
if (second)
27322741
second = second->tokAt(-2);

test/testsymboldatabase.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,23 +5138,47 @@ class TestSymbolDatabase : public TestFixture {
51385138
ASSERT_EQUALS("", errout.str());
51395139
}
51405140

5141-
void symboldatabase104() { // #11535
5142-
GET_SYMBOL_DB("struct S {\n"
5143-
" void f1(char* const c);\n"
5144-
" void f2(char* const c);\n"
5145-
" void f3(char* const);\n"
5146-
" void f4(char* c);\n"
5147-
" void f5(char* c);\n"
5148-
" void f6(char*);\n"
5149-
"};\n"
5150-
"void S::f1(char* c) {}\n"
5151-
"void S::f2(char*) {}\n"
5152-
"void S::f3(char* c) {}\n"
5153-
"void S::f4(char* const c) {}\n"
5154-
"void S::f5(char* const) {}\n"
5155-
"void S::f6(char* const c) {}\n");
5156-
ASSERT(db != nullptr);
5157-
ASSERT_EQUALS("", errout.str());
5141+
void symboldatabase104() {
5142+
const bool oldDebug = settings1.debugwarnings;
5143+
settings1.debugwarnings = true;
5144+
{
5145+
GET_SYMBOL_DB("struct S {\n" // #11535
5146+
" void f1(char* const c);\n"
5147+
" void f2(char* const c);\n"
5148+
" void f3(char* const);\n"
5149+
" void f4(char* c);\n"
5150+
" void f5(char* c);\n"
5151+
" void f6(char*);\n"
5152+
"};\n"
5153+
"void S::f1(char* c) {}\n"
5154+
"void S::f2(char*) {}\n"
5155+
"void S::f3(char* c) {}\n"
5156+
"void S::f4(char* const c) {}\n"
5157+
"void S::f5(char* const) {}\n"
5158+
"void S::f6(char* const c) {}\n");
5159+
ASSERT(db != nullptr);
5160+
ASSERT_EQUALS("", errout.str());
5161+
}
5162+
{
5163+
GET_SYMBOL_DB("struct S2 {\n" // #11602
5164+
" enum E {};\n"
5165+
"};\n"
5166+
"struct S1 {\n"
5167+
" void f(S2::E) const;\n"
5168+
"};\n"
5169+
"void S1::f(const S2::E) const {}\n");
5170+
ASSERT(db != nullptr);
5171+
ASSERT_EQUALS("", errout.str());
5172+
}
5173+
{
5174+
GET_SYMBOL_DB("struct S {\n"
5175+
" void f(const bool b = false);\n"
5176+
"};\n"
5177+
"void S::f(const bool b) {}\n");
5178+
ASSERT(db != nullptr);
5179+
ASSERT_EQUALS("", errout.str());
5180+
}
5181+
settings1.debugwarnings = oldDebug;
51585182
}
51595183

51605184
void createSymbolDatabaseFindAllScopes1() {

0 commit comments

Comments
 (0)