Fix valueFlowConditionExpressions bailout for C++ casts (refs #10045) (#5472)

This commit is contained in:
chrchr-github 2023-09-22 18:19:36 +02:00 committed by GitHub
parent c527af9042
commit bba96c5c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -1486,13 +1486,13 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
tok = tok->linkAt(1); tok = tok->linkAt(1);
continue; continue;
} }
if (!tok->isNameOnly()) if (!(tok->isNameOnly() || tok->isKeyword()))
continue; continue;
if (tok->type()) if (tok->type())
continue; continue;
if (Token::Match(tok->next(), "::|.|(|{|:|%var%")) if (Token::Match(tok->next(), "::|.|(|{|:|%var%"))
continue; continue;
if (Token::Match(tok->next(), "&|&&|* )|,|%var%")) if (Token::Match(tok->next(), "&|&&|* )|,|%var%|const"))
continue; continue;
// Very likely a typelist // Very likely a typelist
if (Token::Match(tok->tokAt(-2), "%type% ,") || Token::Match(tok->next(), ", %type%")) if (Token::Match(tok->tokAt(-2), "%type% ,") || Token::Match(tok->next(), ", %type%"))
@ -1502,6 +1502,8 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
tok = tok->linkAt(1); tok = tok->linkAt(1);
continue; continue;
} }
if (tok->isKeyword())
continue;
// Skip goto labels // Skip goto labels
if (Token::simpleMatch(tok->previous(), "goto")) if (Token::simpleMatch(tok->previous(), "goto"))
continue; continue;

View File

@ -5479,6 +5479,20 @@ private:
const Token* free3 = Token::findsimplematch(free2->next(), "free"); const Token* free3 = Token::findsimplematch(free2->next(), "free");
ASSERT(free3 && free3->isIncompleteVar()); 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() { void enum1() {