Fix incorrect function assignment (#4977)
This commit is contained in:
parent
35a46dfd00
commit
31e714cded
|
@ -1100,16 +1100,18 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
|
|||
if (tok->next()->str() == ">" && !tok->next()->link())
|
||||
continue;
|
||||
|
||||
bool isTemplateArg = false;
|
||||
if (tok->next()->str() != "(") {
|
||||
const Token *start = tok;
|
||||
while (Token::Match(start->tokAt(-2), "%name% ::"))
|
||||
start = start->tokAt(-2);
|
||||
if (!Token::Match(start->previous(), "[(,<=]") && !Token::Match(start->tokAt(-2), "[(,<=] &") && !Token::Match(start, "%name% ;"))
|
||||
continue;
|
||||
isTemplateArg = Token::simpleMatch(start->previous(), "<") || Token::simpleMatch(start->tokAt(-2), "<");
|
||||
}
|
||||
|
||||
const Function *function = findFunction(tok);
|
||||
if (!function)
|
||||
if (!function || (isTemplateArg && function->isConstructor()))
|
||||
continue;
|
||||
|
||||
const_cast<Token *>(tok)->function(function);
|
||||
|
|
|
@ -443,6 +443,7 @@ private:
|
|||
TEST_CASE(findFunction44); // #11182
|
||||
TEST_CASE(findFunction45);
|
||||
TEST_CASE(findFunction46);
|
||||
TEST_CASE(findFunction47);
|
||||
TEST_CASE(findFunctionContainer);
|
||||
TEST_CASE(findFunctionExternC);
|
||||
TEST_CASE(findFunctionGlobalScope); // ::foo
|
||||
|
@ -7149,6 +7150,18 @@ private:
|
|||
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
|
||||
}
|
||||
|
||||
void findFunction47() {
|
||||
GET_SYMBOL_DB("struct S {\n"
|
||||
" S() {}\n"
|
||||
" std::list<S> l;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
const Token* typeTok = Token::findsimplematch(tokenizer.tokens(), "S >");
|
||||
ASSERT(typeTok && typeTok->type());
|
||||
ASSERT(typeTok->type()->name() == "S");
|
||||
ASSERT_EQUALS(1, typeTok->type()->classDef->linenr());
|
||||
}
|
||||
|
||||
void findFunctionContainer() {
|
||||
{
|
||||
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
||||
|
|
Loading…
Reference in New Issue