Skip to content

Commit

Permalink
Fix valueFlowConditionExpressions bailout for C++ casts (refs #10045) (
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 22, 2023
1 parent c527af9 commit bba96c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,13 +1486,13 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
tok = tok->linkAt(1);
continue;
}
if (!tok->isNameOnly())
if (!(tok->isNameOnly() || tok->isKeyword()))
continue;
if (tok->type())
continue;
if (Token::Match(tok->next(), "::|.|(|{|:|%var%"))
continue;
if (Token::Match(tok->next(), "&|&&|* )|,|%var%"))
if (Token::Match(tok->next(), "&|&&|* )|,|%var%|const"))
continue;
// Very likely a typelist
if (Token::Match(tok->tokAt(-2), "%type% ,") || Token::Match(tok->next(), ", %type%"))
Expand All @@ -1502,6 +1502,8 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
tok = tok->linkAt(1);
continue;
}
if (tok->isKeyword())
continue;
// Skip goto labels
if (Token::simpleMatch(tok->previous(), "goto"))
continue;
Expand Down
14 changes: 14 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5479,6 +5479,20 @@ class TestSymbolDatabase : public TestFixture {
const Token* free3 = Token::findsimplematch(free2->next(), "free");
ASSERT(free3 && free3->isIncompleteVar());
}
{
GET_SYMBOL_DB("void f(QObject* p, const char* s) {\n"
" QWidget* w = dynamic_cast<QWidget*>(p);\n"
" g(static_cast<const std::string>(s));\n"
" const std::uint64_t* const data = nullptr;\n"
"}\n");
ASSERT(db && errout.str().empty());
const Token* qw = Token::findsimplematch(tokenizer.tokens(), "QWidget * >");
ASSERT(qw && !qw->isIncompleteVar());
const Token* s = Token::findsimplematch(qw, "string >");
ASSERT(s && !s->isIncompleteVar());
const Token* u = Token::findsimplematch(s, "uint64_t");
ASSERT(u && !u->isIncompleteVar());
}
}

void enum1() {
Expand Down

0 comments on commit bba96c5

Please sign in to comment.