Skip to content

Commit 31e714c

Browse files
Fix incorrect function assignment (#4977)
1 parent 35a46df commit 31e714c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,16 +1100,18 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
11001100
if (tok->next()->str() == ">" && !tok->next()->link())
11011101
continue;
11021102

1103+
bool isTemplateArg = false;
11031104
if (tok->next()->str() != "(") {
11041105
const Token *start = tok;
11051106
while (Token::Match(start->tokAt(-2), "%name% ::"))
11061107
start = start->tokAt(-2);
11071108
if (!Token::Match(start->previous(), "[(,<=]") && !Token::Match(start->tokAt(-2), "[(,<=] &") && !Token::Match(start, "%name% ;"))
11081109
continue;
1110+
isTemplateArg = Token::simpleMatch(start->previous(), "<") || Token::simpleMatch(start->tokAt(-2), "<");
11091111
}
11101112

11111113
const Function *function = findFunction(tok);
1112-
if (!function)
1114+
if (!function || (isTemplateArg && function->isConstructor()))
11131115
continue;
11141116

11151117
const_cast<Token *>(tok)->function(function);

test/testsymboldatabase.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ class TestSymbolDatabase : public TestFixture {
443443
TEST_CASE(findFunction44); // #11182
444444
TEST_CASE(findFunction45);
445445
TEST_CASE(findFunction46);
446+
TEST_CASE(findFunction47);
446447
TEST_CASE(findFunctionContainer);
447448
TEST_CASE(findFunctionExternC);
448449
TEST_CASE(findFunctionGlobalScope); // ::foo
@@ -7149,6 +7150,18 @@ class TestSymbolDatabase : public TestFixture {
71497150
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
71507151
}
71517152

7153+
void findFunction47() {
7154+
GET_SYMBOL_DB("struct S {\n"
7155+
" S() {}\n"
7156+
" std::list<S> l;\n"
7157+
"};\n");
7158+
ASSERT_EQUALS("", errout.str());
7159+
const Token* typeTok = Token::findsimplematch(tokenizer.tokens(), "S >");
7160+
ASSERT(typeTok && typeTok->type());
7161+
ASSERT(typeTok->type()->name() == "S");
7162+
ASSERT_EQUALS(1, typeTok->type()->classDef->linenr());
7163+
}
7164+
71527165
void findFunctionContainer() {
71537166
{
71547167
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"

0 commit comments

Comments
 (0)