Set function pointer for ::f (#5028)

This commit is contained in:
chrchr-github 2023-05-02 22:53:21 +02:00 committed by GitHub
parent 25183ff484
commit 7e0ddd3669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -1105,7 +1105,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
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% ;"))
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), "<");
}
@ -5577,8 +5577,8 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const
if (tok1->strAt(-1) == "::") {
currScope = &scopeList.front();
if (Token::Match(tok1, "%name% ("))
return currScope->findFunction(tok);
if (const Function* f = currScope->findFunction(tok))
return f;
currScope = currScope->findRecordInNestedList(tok1->str());
}

View File

@ -3522,6 +3522,18 @@ private:
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (style) Parameter 'p' can be declared as pointer to const. "
"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s).\n",
errout.str());
check("typedef void (*cb_t)(int*);\n"
"void cb(int* p) {\n"
" if (*p) {}\n"
"}\n"
"void g(cb_t);\n"
"void f() {\n"
" g(::cb);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (style) Parameter 'p' can be declared as pointer to const. "
"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s).\n",
errout.str());
}
void switchRedundantAssignmentTest() {