Fixed #11904 (One more related fix for Scope::findFunction) (#5383)

This commit is contained in:
Daniel Marjamäki 2023-08-31 23:12:54 +02:00 committed by GitHub
parent 44c149e51b
commit 85332b2af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 17 deletions

View File

@ -5688,21 +5688,25 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
return matches[0]; return matches[0];
// Prioritize matches in derived scopes // Prioritize matches in derived scopes
const Function* ret = nullptr; for (const auto& fb : { fallback1Func, fallback2Func }) {
for (int i = 0; i < fallback1Func.size(); ++i) { const Function* ret = nullptr;
if (std::find(matches.cbegin(), matches.cend(), fallback1Func[i]) == matches.cend()) for (int i = 0; i < fb.size(); ++i) {
continue; if (std::find(matches.cbegin(), matches.cend(), fb[i]) == matches.cend())
if (this == fallback1Func[i]->nestedIn) { continue;
if (!ret) if (this == fb[i]->nestedIn) {
ret = fallback1Func[i]; if (!ret)
else { ret = fb[i];
ret = nullptr; else {
break; ret = nullptr;
break;
}
} }
} }
if (ret)
return ret;
} }
return ret; return nullptr;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -7306,12 +7306,23 @@ private:
} }
void findFunction50() { void findFunction50() {
GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n" {
"struct D: B { D(); void init(unsigned int value); };\n" GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n"
"D::D() { init(0); }\n" "struct D: B { D(); void init(unsigned int value); };\n"
"void D::init(unsigned int value) {}\n"); "D::D() { init(0); }\n"
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0 ) ;"); "void D::init(unsigned int value) {}\n");
ASSERT(call && call->function() && call->function()->functionScope); const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0 ) ;");
ASSERT(call && call->function() && call->function()->functionScope);
}
{
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(0ULL); }\n"
"void D::init(unsigned int value) {}\n");
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0ULL ) ;");
ASSERT(call && call->function() && call->function()->functionScope);
}
} }
void findFunctionContainer() { void findFunctionContainer() {