From 6914f375e1af52f2975bc8beeb5735cabcb1070e Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Thu, 28 Jan 2021 06:38:36 -0500 Subject: [PATCH] fix #10135 ("debug: Executable scope 'what' with unknown function." with custom std::exception) (#3089) --- lib/symboldatabase.cpp | 19 +++++++++---------- test/testsymboldatabase.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5c7a29c5f..2b91b8eab 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2429,10 +2429,17 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se while (first->str() == second->str() && first->isLong() == second->isLong() && first->isUnsigned() == second->isUnsigned()) { - if (first->str() == "(") openParen++; + // at end of argument list + else if (first->str() == ")") { + if (openParen == 1) + return true; + else + --openParen; + } + // skip optional type information if (Token::Match(first->next(), "struct|enum|union|class")) first = first->next(); @@ -2447,14 +2454,6 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se !Token::Match(second->next(), "const %type% %name%| [")) second = second->next(); - // at end of argument list - if (first->str() == ")") { - if (openParen == 1) - return true; - else - --openParen; - } - // skip default value assignment else if (first->next()->str() == "=") { first = first->nextArgument(); @@ -2506,7 +2505,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se first = first->next(); // argument list has different number of arguments - else if (second->str() == ")") + else if (openParen == 1 && second->str() == ")" && first->str() != ")") break; // ckeck for type * x == type x[] diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 005857339..1bfb50f3e 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -404,6 +404,7 @@ private: TEST_CASE(findFunction37); // #10124 TEST_CASE(findFunction38); // #10125 TEST_CASE(findFunction39); // #10127 + TEST_CASE(findFunction40); // #10135 TEST_CASE(findFunctionContainer); TEST_CASE(findFunctionExternC); TEST_CASE(findFunctionGlobalScope); // ::foo @@ -6343,6 +6344,22 @@ private: ASSERT_EQUALS(8, functok->function()->tokenDef->linenr()); } + void findFunction40() { // #10135 + GET_SYMBOL_DB("class E : public std::exception {\n" + "public:\n" + " const char* what() const noexcept override;\n" + "};\n" + "const char* E::what() const noexcept {\n" + " return nullptr;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + const Token *functok = Token::findsimplematch(tokenizer.tokens(), "what ( ) const noexcept {"); + ASSERT(functok); + ASSERT(functok->function()); + ASSERT(functok->function()->name() == "what"); + ASSERT_EQUALS(3, functok->function()->tokenDef->linenr()); + } + void findFunctionContainer() { { GET_SYMBOL_DB("void dostuff(std::vector v);\n"