Fix incorrect function assignment (#4977)

This commit is contained in:
chrchr-github 2023-04-19 06:53:47 +02:00 committed by GitHub
parent 35a46dfd00
commit 31e714cded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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);

View File

@ -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"