Skip to content

Commit

Permalink
Fix #11888 FP knownPointerToBool with incorrect overload match
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 21, 2023
1 parent 03b952d commit 869af84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7686,7 +7686,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
}

if (call->typeScope != nullptr || func->typeScope != nullptr) {
if (call->typeScope != func->typeScope)
if (call->typeScope != func->typeScope && !(call->typeScope->definedType && call->typeScope->definedType->isDerivedFrom(func->typeScope->className)))
return ValueType::MatchResult::NOMATCH;
}

Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction46);
TEST_CASE(findFunction47);
TEST_CASE(findFunction48);
TEST_CASE(findFunction49); // #11888
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -7286,6 +7287,22 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(1, typeTok->type()->classDef->linenr());
}

void findFunction49() {
GET_SYMBOL_DB("struct B {};\n"
"struct D : B {};\n"
"void f(bool = false, bool = true);\n"
"void f(B*, bool, bool = true);\n"
"void g() {\n"
" D d;\n"
" f(&d, true);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token* ftok = Token::findsimplematch(tokenizer.tokens(), "f ( &");
ASSERT(ftok && ftok->function());
ASSERT(ftok->function()->name() == "f");
ASSERT_EQUALS(4, ftok->function()->tokenDef->linenr());
}

void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
Expand Down

0 comments on commit 869af84

Please sign in to comment.