Skip to content

Commit 85332b2

Browse files
authored
Fixed #11904 (One more related fix for Scope::findFunction) (#5383)
1 parent 44c149e commit 85332b2

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5688,21 +5688,25 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
56885688
return matches[0];
56895689

56905690
// Prioritize matches in derived scopes
5691-
const Function* ret = nullptr;
5692-
for (int i = 0; i < fallback1Func.size(); ++i) {
5693-
if (std::find(matches.cbegin(), matches.cend(), fallback1Func[i]) == matches.cend())
5694-
continue;
5695-
if (this == fallback1Func[i]->nestedIn) {
5696-
if (!ret)
5697-
ret = fallback1Func[i];
5698-
else {
5699-
ret = nullptr;
5700-
break;
5691+
for (const auto& fb : { fallback1Func, fallback2Func }) {
5692+
const Function* ret = nullptr;
5693+
for (int i = 0; i < fb.size(); ++i) {
5694+
if (std::find(matches.cbegin(), matches.cend(), fb[i]) == matches.cend())
5695+
continue;
5696+
if (this == fb[i]->nestedIn) {
5697+
if (!ret)
5698+
ret = fb[i];
5699+
else {
5700+
ret = nullptr;
5701+
break;
5702+
}
57015703
}
57025704
}
5705+
if (ret)
5706+
return ret;
57035707
}
57045708

5705-
return ret;
5709+
return nullptr;
57065710
}
57075711

57085712
//---------------------------------------------------------------------------

test/testsymboldatabase.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7306,12 +7306,23 @@ class TestSymbolDatabase : public TestFixture {
73067306
}
73077307

73087308
void findFunction50() {
7309-
GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n"
7310-
"struct D: B { D(); void init(unsigned int value); };\n"
7311-
"D::D() { init(0); }\n"
7312-
"void D::init(unsigned int value) {}\n");
7313-
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0 ) ;");
7314-
ASSERT(call && call->function() && call->function()->functionScope);
7309+
{
7310+
GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n"
7311+
"struct D: B { D(); void init(unsigned int value); };\n"
7312+
"D::D() { init(0); }\n"
7313+
"void D::init(unsigned int value) {}\n");
7314+
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0 ) ;");
7315+
ASSERT(call && call->function() && call->function()->functionScope);
7316+
}
7317+
7318+
{
7319+
GET_SYMBOL_DB("struct B { B(); void init(unsigned int value); };\n"
7320+
"struct D: B { D(); void init(unsigned int value); };\n"
7321+
"D::D() { init(0ULL); }\n"
7322+
"void D::init(unsigned int value) {}\n");
7323+
const Token* call = Token::findsimplematch(tokenizer.tokens(), "init ( 0ULL ) ;");
7324+
ASSERT(call && call->function() && call->function()->functionScope);
7325+
}
73157326
}
73167327

73177328
void findFunctionContainer() {

0 commit comments

Comments
 (0)