Skip to content

Commit f837929

Browse files
Fix #12910 FP containerOutOfBounds with overloaded template function (danmar#7453)
1 parent 20681a3 commit f837929

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6018,7 +6018,9 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
60186018
matches.erase(itPure);
60196019

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

60246026
// Prioritize matches in derived scopes

test/testsymboldatabase.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ class TestSymbolDatabase : public TestFixture {
528528
TEST_CASE(findFunction57);
529529
TEST_CASE(findFunction58); // #13310
530530
TEST_CASE(findFunction59);
531+
TEST_CASE(findFunction60);
531532
TEST_CASE(findFunctionRef1);
532533
TEST_CASE(findFunctionRef2); // #13328
533534
TEST_CASE(findFunctionContainer);
@@ -8597,6 +8598,26 @@ class TestSymbolDatabase : public TestFixture {
85978598
ASSERT_EQUALS(foo->function()->tokenDef->linenr(), 1);
85988599
}
85998600

8601+
void findFunction60() { // #12910
8602+
GET_SYMBOL_DB("template <class T>\n"
8603+
"void fun(T& t, bool x = false) {\n"
8604+
" t.push_back(0);\n"
8605+
"}\n"
8606+
"template <class T>\n"
8607+
"void fun(bool x = false) {\n"
8608+
" T t;\n"
8609+
" fun(t, x);\n"
8610+
"}\n"
8611+
"int f() {\n"
8612+
" fun<std::vector<int>>(true);\n"
8613+
" std::vector<int> v;\n"
8614+
" fun(v);\n"
8615+
" return v.back();\n"
8616+
"}\n");
8617+
const Token* fun = Token::findsimplematch(tokenizer.tokens(), "fun ( v");
8618+
ASSERT(fun && !fun->function());
8619+
}
8620+
86008621
void findFunctionRef1() {
86018622
GET_SYMBOL_DB("struct X {\n"
86028623
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)