Fixed #9618 (isCast flag not set for c++ casts)
This commit is contained in:
parent
921887a281
commit
ae0a73a538
|
@ -4638,6 +4638,14 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
// Link < with >
|
||||
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 <") && Token::simpleMatch(tok->linkAt(1), "> (")) {
|
||||
tok = tok->linkAt(1)->next();
|
||||
tok->isCast(true);
|
||||
}
|
||||
}
|
||||
|
||||
// specify array size
|
||||
arraySize();
|
||||
|
||||
|
|
|
@ -487,6 +487,8 @@ private:
|
|||
TEST_CASE(unknownType); // #8952
|
||||
|
||||
TEST_CASE(unknownMacroBeforeReturn);
|
||||
|
||||
TEST_CASE(cppcast);
|
||||
}
|
||||
|
||||
std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
|
@ -8335,6 +8337,22 @@ private:
|
|||
void unknownMacroBeforeReturn() {
|
||||
ASSERT_THROW(tokenizeAndStringify("int f() { X return 0; }"), InternalError);
|
||||
}
|
||||
|
||||
void cppcast() {
|
||||
const char code[] = "a = const_cast<int>(x);\n"
|
||||
"a = dynamic_cast<int>(x);\n"
|
||||
"a = reinterpret_cast<int>(x);\n"
|
||||
"a = static_cast<int>(x);\n";
|
||||
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||
ASSERT_EQUALS(tok->str() == "(", tok->isCast());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue