From 55292d476a023ba2fe71f5bc83b19880f67ff904 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:35:58 +0100 Subject: [PATCH] Fix #11535 "debug: Executable scope 'x' with unknown function" (#4770) --- lib/symboldatabase.cpp | 18 ++++++++++++++---- test/testsymboldatabase.cpp | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e70aa223b..f1b68d426 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2774,11 +2774,21 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se ((first->strAt(2) != "const" && second->strAt(2) == "const") || (first->strAt(2) == "const" && second->strAt(2) != "const"))) { if (first->strAt(2) != "const") { - first = first->next(); - second = second->tokAt(2); + if (Token::Match(first->tokAt(2), "%name%| ,|)") && Token::Match(second->tokAt(3), "%name%| ,|)")) { + first = first->tokAt(Token::Match(first->tokAt(2), "%name%") ? 2 : 1); + second = second->tokAt(Token::Match(second->tokAt(3), "%name%") ? 3 : 2); + } else { + first = first->next(); + second = second->tokAt(2); + } } else { - first = first->tokAt(2); - second = second->next(); + if (Token::Match(second->tokAt(2), "%name%| ,|)") && Token::Match(first->tokAt(3), "%name%| ,|)")) { + first = first->tokAt(Token::Match(first->tokAt(3), "%name%") ? 3 : 2); + second = second->tokAt(Token::Match(second->tokAt(2), "%name%") ? 2 : 1); + } else { + first = first->tokAt(2); + second = second->next(); + } } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e2d99725d..623da2a79 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -367,6 +367,7 @@ private: TEST_CASE(symboldatabase101); TEST_CASE(symboldatabase102); TEST_CASE(symboldatabase103); + TEST_CASE(symboldatabase104); TEST_CASE(createSymbolDatabaseFindAllScopes1); TEST_CASE(createSymbolDatabaseFindAllScopes2); @@ -5075,6 +5076,25 @@ private: 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 createSymbolDatabaseFindAllScopes1() { GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }"); ASSERT(db->scopeList.size() == 3);