Partial fix for #10968 FN detect always false/true comparison of function with constant (#5480)

This commit is contained in:
chrchr-github 2023-09-25 22:18:07 +02:00 committed by GitHub
parent 3fd00c19df
commit 99e38cf8f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1103,7 +1103,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
// Set function call pointers
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
if (tok->isName() && !tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% [{(,)>;]") && !isReservedName(tok->str())) {
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;

View File

@ -450,6 +450,7 @@ private:
TEST_CASE(findFunction49); // #11888
TEST_CASE(findFunction50); // #11904 - method with same name and arguments in derived class
TEST_CASE(findFunction51); // #11975 - method with same name in derived class
TEST_CASE(findFunction52);
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
@ -7558,6 +7559,16 @@ private:
}
}
void findFunction52() {
GET_SYMBOL_DB("int g();\n"
"void f() {\n"
" if (g != 0) {}\n"
"}\n");
const Token* g = Token::findsimplematch(tokenizer.tokens(), "g !=");
ASSERT(g->function() && g->function()->tokenDef);
ASSERT(g->function()->tokenDef->linenr() == 1);
}
void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"