Skip to content

Commit

Permalink
Partial fix for #10968 FN detect always false/true comparison of func…
Browse files Browse the repository at this point in the history
…tion with constant (#5480)
  • Loading branch information
chrchr-github authored Sep 25, 2023
1 parent 3fd00c1 commit 99e38cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ class TestSymbolDatabase : public TestFixture {
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
Expand Down Expand Up @@ -7558,6 +7559,16 @@ class TestSymbolDatabase : public TestFixture {
}
}

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"
Expand Down

0 comments on commit 99e38cf

Please sign in to comment.