From 85332b2af6ce84ea4d52cd3013f53ea64fc990d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 Aug 2023 23:12:54 +0200 Subject: [PATCH] Fixed #11904 (One more related fix for Scope::findFunction) (#5383) --- lib/symboldatabase.cpp | 26 +++++++++++++++----------- test/testsymboldatabase.cpp | 23 +++++++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1e30bec9d..6ad1915c2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5688,21 +5688,25 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const return matches[0]; // 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; + for (const auto& fb : { fallback1Func, fallback2Func }) { + const Function* ret = nullptr; + for (int i = 0; i < fb.size(); ++i) { + if (std::find(matches.cbegin(), matches.cend(), fb[i]) == matches.cend()) + continue; + if (this == fb[i]->nestedIn) { + if (!ret) + ret = fb[i]; + else { + ret = nullptr; + break; + } } } + if (ret) + return ret; } - return ret; + return nullptr; } //--------------------------------------------------------------------------- diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a78b6ffc5..aaf934775 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -7306,12 +7306,23 @@ private: } 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); + { + 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); + } + + { + 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() {