Skip to content

Commit

Permalink
Fix #12219 FP constParameterCallback for template argument (#5695)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 25, 2023
1 parent 1d3f9be commit c1f6132
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,23 +1101,18 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
}

// Set function call pointers
const Token* inTemplateArg = nullptr;
for (Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
if (inTemplateArg == nullptr && tok->link() && tok->str() == "<")
inTemplateArg = tok->link();
if (inTemplateArg == tok)
inTemplateArg = nullptr;
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;]")) && !isReservedName(tok->str())) {
if (tok->next()->str() == ">" && !tok->next()->link())
continue;

bool isTemplateArg = false;
if (!Token::Match(tok->next(), "(|{")) {
const Token *start = tok;
while (Token::Match(start->tokAt(-2), "%name% ::"))
start = start->tokAt(-2);
if (!Token::Match(start->previous(), "[(,<=]") && !Token::simpleMatch(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 || (isTemplateArg && function->isConstructor()))
if (!function || (inTemplateArg && function->isConstructor()))
continue;

tok->function(function);
Expand Down
33 changes: 33 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction51); // #11975 - method with same name in derived class
TEST_CASE(findFunction52);
TEST_CASE(findFunction53);
TEST_CASE(findFunction54);
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -7733,6 +7734,38 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(S->function()->isConstructor());
}

void findFunction54() {
{
GET_SYMBOL_DB("struct S {\n"
" explicit S(int& r) { if (r) {} }\n"
" bool f(const std::map<int, S>& m);\n"
"};\n");
const Token* S = Token::findsimplematch(tokenizer.tokens(), "S (");
ASSERT(S && S->function());
ASSERT(S->function()->isConstructor());
ASSERT(!S->function()->functionPointerUsage);
S = Token::findsimplematch(S->next(), "S >");
ASSERT(S && S->type());
ASSERT_EQUALS(S->type()->name(), "S");
}
{
GET_SYMBOL_DB("struct S {\n"
" explicit S(int& r) { if (r) {} }\n"
" bool f(const std::map<int, S, std::allocator<S>>& m);\n"
"};\n");
const Token* S = Token::findsimplematch(tokenizer.tokens(), "S (");
ASSERT(S && S->function());
ASSERT(S->function()->isConstructor());
ASSERT(!S->function()->functionPointerUsage);
S = Token::findsimplematch(S->next(), "S ,");
ASSERT(S && S->type());
ASSERT_EQUALS(S->type()->name(), "S");
S = Token::findsimplematch(S->next(), "S >");
ASSERT(S && S->type());
ASSERT_EQUALS(S->type()->name(), "S");
}
}

void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
Expand Down

0 comments on commit c1f6132

Please sign in to comment.