diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index fadcbebc2..3881ba134 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4310,7 +4310,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const // check if all arguments matched if (same == hasToBe) { - if (constFallback) + if (constFallback || (!requireConst && func->isConst())) fallback1Func = func; else return func; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 91918f14c..d89a8664f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -336,6 +336,7 @@ private: TEST_CASE(findFunction18); TEST_CASE(findFunction19); TEST_CASE(findFunction20); // #8280 + TEST_CASE(findFunction21); TEST_CASE(noexceptFunction1); TEST_CASE(noexceptFunction2); @@ -5408,6 +5409,25 @@ private: ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 12); } + void findFunction21() { // # 8558 + GET_SYMBOL_DB("struct foo {\n" + " int GetThing( ) const { return m_thing; }\n" + " int* GetThing( ) { return &m_thing; }\n" + "};\n" + "\n" + "void f(foo *myFoo) {\n" + " int* myThing = myFoo->GetThing();\n" + "}"); + + ASSERT(db != nullptr); + + const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "myFoo . GetThing ( ) ;"); + + const Function *f = tok1 && tok1->tokAt(2) ? tok1->tokAt(2)->function() : nullptr; + ASSERT(f != nullptr); + ASSERT_EQUALS(true, f && f->tokenDef->linenr() == 3); + } + #define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isNoExcept());