Fix #12219 FP constParameterCallback for template argument (#5695)

This commit is contained in:
chrchr-github 2023-11-25 22:57:07 +01:00 committed by GitHub
parent 1d3f9beb21
commit c1f6132745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 11 deletions

View File

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

View File

@ -454,6 +454,7 @@ private:
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
@ -7733,6 +7734,38 @@ private:
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"