fix #10135 ("debug: Executable scope 'what' with unknown function." with custom std::exception) (#3089)

This commit is contained in:
IOBYTE 2021-01-28 06:38:36 -05:00 committed by GitHub
parent e17d22eb87
commit 6914f375e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -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[]

View File

@ -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<int> v);\n"