Skip to content

Fix #12910 FP containerOutOfBounds with overloaded template function #7453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6018,7 +6018,9 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
matches.erase(itPure);

// Only one candidate left
if (matches.size() == 1)
if (matches.size() == 1 && std::none_of(functionList.begin(), functionList.end(), [tok](const Function& f) {
return startsWith(f.name(), tok->str() + " <");
}))
return matches[0];

// Prioritize matches in derived scopes
Expand Down
21 changes: 21 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction57);
TEST_CASE(findFunction58); // #13310
TEST_CASE(findFunction59);
TEST_CASE(findFunction60);
TEST_CASE(findFunctionRef1);
TEST_CASE(findFunctionRef2); // #13328
TEST_CASE(findFunctionContainer);
Expand Down Expand Up @@ -8573,6 +8574,26 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(foo->function()->tokenDef->linenr(), 1);
}

void findFunction60() { // #12910
GET_SYMBOL_DB("template <class T>\n"
"void fun(T& t, bool x = false) {\n"
" t.push_back(0);\n"
"}\n"
"template <class T>\n"
"void fun(bool x = false) {\n"
" T t;\n"
" fun(t, x);\n"
"}\n"
"int f() {\n"
" fun<std::vector<int>>(true);\n"
" std::vector<int> v;\n"
" fun(v);\n"
" return v.back();\n"
"}\n");
const Token* fun = Token::findsimplematch(tokenizer.tokens(), "fun ( v");
ASSERT(fun && !fun->function());
}

void findFunctionRef1() {
GET_SYMBOL_DB("struct X {\n"
" const std::vector<int> getInts() const & { return mInts; }\n"
Expand Down
Loading