Fix #11904 (Scope::findFunction: better handling when non-virtual method with same name and arguments exists both in base class and derived class) (#5379)
This commit is contained in:
parent
ad1caa8100
commit
1b061564d9
|
@ -5467,7 +5467,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
|
||||
addMatchingFunctions(this);
|
||||
|
||||
// check in anonumous namespaces
|
||||
// check in anonymous namespaces
|
||||
for (const Scope *nestedScope : nestedList) {
|
||||
if (nestedScope->type == eNamespace && nestedScope->className.empty())
|
||||
addMatchingFunctions(nestedScope);
|
||||
|
@ -5687,7 +5687,22 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
if (matches.size() == 1)
|
||||
return matches[0];
|
||||
|
||||
return nullptr;
|
||||
// Prioritize matches in derived scopes
|
||||
const Function* ret = nullptr;
|
||||
for (int i = 0; i < fallback1Func.size(); ++i) {
|
||||
if (std::find(matches.cbegin(), matches.cend(), fallback1Func[i]) == matches.cend())
|
||||
continue;
|
||||
if (this == fallback1Func[i]->nestedIn) {
|
||||
if (!ret)
|
||||
ret = fallback1Func[i];
|
||||
else {
|
||||
ret = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -442,6 +442,7 @@ private:
|
|||
TEST_CASE(findFunction47);
|
||||
TEST_CASE(findFunction48);
|
||||
TEST_CASE(findFunction49); // #11888
|
||||
TEST_CASE(findFunction50); // #11904 - method with same name and arguments in derived class
|
||||
TEST_CASE(findFunctionContainer);
|
||||
TEST_CASE(findFunctionExternC);
|
||||
TEST_CASE(findFunctionGlobalScope); // ::foo
|
||||
|
@ -7304,6 +7305,15 @@ private:
|
|||
ASSERT_EQUALS(4, ftok->function()->tokenDef->linenr());
|
||||
}
|
||||
|
||||
void findFunction50() {
|
||||
GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n"
|
||||
"struct D: B { D(); void init(unsigned int value); };\n"
|
||||
"D::D() { init(0); }\n"
|
||||
"void D::init(unsigned int value) {}\n");
|
||||
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0 ) ;");
|
||||
ASSERT(call && call->function() && call->function()->functionScope);
|
||||
}
|
||||
|
||||
void findFunctionContainer() {
|
||||
{
|
||||
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
||||
|
|
Loading…
Reference in New Issue