Skip to content

Commit

Permalink
C++ casts
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 5, 2024
1 parent 5ec0f77 commit 992494a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5414,6 +5414,21 @@ void Tokenizer::createLinks2()
}
}

void Tokenizer::markCppCasts()
{
if (isC())
return;
for (Token* tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <")) {
if (!Token::simpleMatch(tok->linkAt(1), "> ("))
syntaxError(tok);
tok = tok->linkAt(1)->next();
tok->isCast(true);
}
}

}

void Tokenizer::sizeofAddParentheses()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -5807,14 +5822,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
createLinks2();

// Mark C++ casts
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <")) {
if (!Token::simpleMatch(tok->linkAt(1), "> ("))
syntaxError(tok);
tok = tok->linkAt(1)->next();
tok->isCast(true);
}
}
markCppCasts();

// specify array size
arraySize();
Expand Down
5 changes: 5 additions & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ class CPPCHECKLIB Tokenizer {
*/
void createLinks2();

/**
* Set isCast() for C++ casts
*/
void markCppCasts();

public:

/** Syntax error */
Expand Down

0 comments on commit 992494a

Please sign in to comment.